w3resource
SQL exercises

SQL Exercises: Latest order date (comes last) along with the total purchase amount and commission

SQL Formatting Output: Exercise-10 with Solution

Write a SQL statement make a report with order date in such a manner that, the latest order date will come last along with the total purchase amount and total commission (15% for all salesmen) for that date.

Sample table: orders


Sample Solution:

SELECT ord_date, SUM(purch_amt), 
SUM(purch_amt)*.15 
FROM orders 
GROUP BY ord_date 
ORDER BY ord_date;

Output of the Query:

ord_date	sum		?column?
2012-04-25	3045.60		456.8400
2012-06-27	250.45		37.5675
2012-07-27	2400.60		360.0900
2012-08-17	185.79		27.8685
2012-09-10	6979.15		1046.8725
2012-10-05	215.76		32.3640
2012-10-10	4463.83		669.5745

Explanation :

Syntax of make a report with order date in such a manner that, the latest order date will comes first along with the total purchase amount and total commission for that date

Pictorial presentation :

Result of a report with order date in such a manner that, the latest order date will comes first along with the total purchase amount and total commission for that date

Query Visualization:

Duration:

Query visualization of Latest order date (comes last) along with the total purchase amount and commission - Duration

Rows:

Query visualization of Latest order date (comes last) along with the total purchase amount and commission - Rows

Cost:

Query visualization of Latest order date (comes last) along with the total purchase amount and commission - Cost

 

Practice Online


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

Previous: Write a SQL statement to make a report with customer ID in such a manner that, the largest number of orders booked by the customer will come first along with their highest purchase amount.
Next: SQL Query on Multiple Tables Exercises Home

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming