Assignment-Aggregates
Assignment-Aggregates
From the following table, write a SQL query to calculate total purchase amount of
all orders. Return total purchase amount.
2. From the following table, write a SQL query to calculate the average purchase
amount of all orders. Return average purchase amount.
4. From the following table, write a SQL query to count the number of customers.
Return number of customers.
6. From the following table, write a SQL query to find the maximum purchase amount.
7. From the following table, write a SQL query to find the minimum purchase
amount.
Sample table: orders
ord_no purch_amt ord_date customer_id salesman_id
---------- ---------- ---------- ----------- -----------
70001 150.5 2012-10-05 3005 5002
70009 270.65 2012-09-10 3001 5005
70002 65.26 2012-10-05 3002 5001
70004 110.5 2012-08-17 3009 5003
70007 948.5 2012-09-10 3005 5002
70005 2400.6 2012-07-27 3007 5001
70008 5760 2012-09-10 3002 5001
70010 1983.43 2012-10-10 3004 5006
70003 2480.4 2012-10-10 3009 5003
70012 250.45 2012-06-27 3008 5002
70011 75.29 2012-08-17 3003 5007
70013 3045.6 2012-04-25 3002 5001
Sample Output:
min
65.26
8. From the following table, write a SQL query to find the highest grade of the
customers in each city. Return city, maximum grade.
10. From the following table, write a SQL query to find the highest purchase amount
ordered by each customer on a particular date. Return, order date and highest
purchase amount.
11. From the following table, write a SQL query to determine the highest purchase
amount made by each salesperson on '2012-08-17'. Return salesperson ID, purchase
amount
12. From the following table, write a SQL query to find the highest order (purchase)
amount by each customer on a particular order date. Filter the result by highest order
(purchase) amount above 2000.00. Return customer id, order date and maximum
purchase amount.
13. From the following table, write a SQL query to find the maximum order (purchase)
amount in the range 2000 - 6000 (Begin and end values are included.) by combination
of each customer and order date. Return customer id, order date and maximum
purchase amount.
14. From the following table, write a SQL query to find the maximum order (purchase)
amount based on the combination of each customer and order date. Filter the rows
for maximum order (purchase) amount is either 2000, 3000, 5760, 6000. Return
customer id, order date and maximum purchase amount.
15. From the following table, write a SQL query to determine the maximum order
amount for each customer. The customer ID should be in the range 3002 and
3007(Begin and end values are included.). Return customer id and maximum
purchase amount.
16. From the following table, write a SQL query to find the maximum order (purchase)
amount for each customer. The customer ID should be in the range 3002 and
3007(Begin and end values are included.). Filter the rows for maximum order
(purchase) amount is higher than 1000. Return customer id and maximum purchase
amount.
18. From the following table, write a SQL query to count all the orders generated on
'2012-08-17'. Return number of orders.
19. From the following table, write a SQL query to count the number of salespeople in
a city. Return number of salespeople.
20. From the following table, write a SQL query to count the number of orders based
on the combination of each order date and salesperson. Return order date,
salesperson id.
21. From the following table, write a SQL query to calculate the average product
price. Return average product price.
22. From the following table, write a SQL query to count the number of products
whose price are higher than or equal to 350. Return number of products.
23. From the following table, write a SQL query to compute the average price for
unique companies. Return average price and company id.
24. From the following table, write a SQL query to compute the sum of the allotment
amount of all departments. Return sum of the allotment amount.
25. From the following table, write a SQL query to count the number of employees in
each department. Return department code and number of employees.