SQL Tasks
This document outlines the instructions for completing five SQL tasks:
Task 1: Extract Year, Month, and Day from Date Attribute
- Write an SQL query that extracts the year, month, and day from the
date
attribute in theorders
table. - Display the extracted values as three separate attributes alongside the
id
attribute and the originaldate
attribute (resulting in a total of five attributes).
Task 2: Add One Day to Date Attribute
- Write an SQL query that adds one day to the
date
attribute in theorders
table. - Display the
id
attribute, the originaldate
attribute, and the result of adding one day.
Task 3: Display Date as Timestamp in Seconds
- Write an SQL query that displays the
date
attribute in theorders
table as the number of seconds since the epoch (timestamp). - To achieve this, identify and apply the appropriate function.
- Display the
id
attribute, the originaldate
attribute, and the result of the function.
Task 4: Count Orders within a Specific Date Range
- Write an SQL query that counts the number of rows in the
orders
table where thedate
attribute falls within the range between 1996-07-10 00:00:00 and 1996-10-08 00:00:00.
Task 5: Create JSON Objects from Order Data
- Write an SQL query that displays the
id
attribute, thedate
attribute, and a JSON object in the format {"id": , "date": } for each row in theorders
table. - Utilize a function to create the JSON object.