Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

SQL Exercises: Find the number of orders booked for each day

SQL Formatting Output: Exercise-2 with Solution

From the following table, write a SQL query to find the number of orders booked for each day. Return the result in a format like "For 2001-10-10 there are 15 orders".

Sample table: orders


Sample Solution:

SELECT ' For',ord_date,',there are', 
COUNT (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.

Relational Algebra Expression:

Relational Algebra Expression: Number of orders booked for each day and display it in a specific format.

Relational Algebra Tree:

Relational Algebra Tree: Number of orders booked for each day and display it in a specific format.

Explanation :

Syntax of find out the number of orders booked for each day and display it in such a format

Pictorial presentation :

Result of find out the number of orders booked for each day and display it in such a format

Practice Online


Query Visualization:

Duration:

Query visualization of Number of orders booked for each day and display it in a specific format - Duration

Rows:

Query visualization of Number of orders booked for each day and display it in a specific format - Rows

Cost:

Query visualization of Number of orders booked for each day and display it in a specific format - Cost

 

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: From the following table, write a SQL query to select all the salespeople. Return salesman_id, name, city, commission with the percent sign (%).
Next: From the following table, write a SQL query to find all the orders. Sort the result-set in ascending order by ord_no. Return all fields.

Test your Programming skills with w3resource's quiz.

What is the difficulty level of this exercise?



SQL: Tips of the Day

SQL Server SELECT into existing table.

INSERT INTO dbo.TABLETWO
SELECT col1, col2
  FROM dbo.TABLEONE
 WHERE col3 LIKE @search_key

This assumes there's only two columns in dbo.TABLETWO - you need to specify the columns otherwise:

INSERT INTO dbo.TABLETWO
  (col1, col2)
SELECT col1, col2
  FROM dbo.TABLEONE
 WHERE col3 LIKE @search_key

Database: SQL Server

Ref: https://bit.ly/3y6tpA3