. Write a SELECT statement that returns these columns from the Orders table: The
ID: 3797358 • Letter: #
Question
. Write a SELECT statement that returns these columns from the Orders table: The order_date column (four screenshots) a.
A column that uses the DATE_FORMAT function to return the four-digit year that’s stored in the order_date column
b. A column that uses the DATE_FORMAT function to return the order_date column in this format: Mon-DD-YYYY. In other words, use abbreviated months and separate each date component with dashes.
c. A column that uses the DATE_FORMAT function to return the order_date column with only the hours and minutes on a 12-hour clock with an am/pm indicator
d. A column that uses the DATE_FORMAT function to return the order_date column in this format: MM/DD/YY HH:MM. In other words, use two-digit months, days, and years and separate them by slashes. Use 2-digit hours and minutes on a 24-hour clock. And use leading zeros for all date/time components.
3. Write a SELECT statement that returns these columns from the Orders table: (two screenshots if you do the extra credit)
a. The card_number column
b. The length of the card_number column
c. The last four digits of the card_number column
d. When you get that working right, add the columns that follow to the result set. This is more difficult because these columns require the use of functions within functions. A column that displays the last four digits of the card_number column in this format: XXXX-XXXX-XXXX-1234. In other words, use Xs for the first 12 digits of the card number and actual numbers for the last four digits of the number
Explanation / Answer
I'm assuming that you have written your DATE_FORMAT function in the file dbo. The declaration of the function i assumed is as follows
DATE_FORMAT(date,format);
where format is "y": return just year
Mon-dd-yyyy: return in this format "August - 22-2018"
MM/DD/YYYY HH:MM:SEC : return in this format
HH:MM return hours and minutes in 12-hour format
Here are my queries follows
1)
a) select dbo.DATE_FORMAT(order_date,"") from Orders;
b) select dbo.DATE_FORMAT(order_date,"Y") from Orders;
c) select dbo.DATE_FORMAT(order_date, "Mon-DD-YYYY") from Orders;
d) select dbo.DATE_FORMAT(order_date, "HH:MM") from Orders;
3)
select card_number, LENGTH(TRIM(card_number)), SUBSTR(card_number,-4,4) Result from Orders;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.