SQL Exercises: Number of orders booked for each day and display it in a specific format
SQL Formatting Output : Exercise-2 with Solution
Write a SQL statement to find out the number of orders booked for each day and display it in such a format like "For 2001-10-10 there are 15 orders".
Sample table: orders
SELECT ' For',ord_date,',there are', COUNT (DISTINCT ord_no),'orders.' FROM orders GROUP BY ord_date;
Output of the Query:
?column? ord_date ?column? count ?column? For 2012-04-25 ,there are 1 orders. For 2012-06-27 ,there are 1 orders. For 2012-07-27 ,there are 1 orders. For 2012-08-17 ,there are 2 orders. For 2012-09-10 ,there are 3 orders. For 2012-10-05 ,there are 2 orders. For 2012-10-10 ,there are 2 orders.
Pictorial presentation :
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a SQL statement to display the commission with the percent sign ( % ) with salesman ID, name and city columns for all the salesmen.
Next: Write a query to display the orders according to the order number arranged by ascending order.
What is the difficulty level of this exercise?