Name: Nidhi Bhutna
Section: CST (Roll no. 25)
University Roll No.: 2019723
ASSIGNMENT – 8
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
Write a SQL query:
1. To calculate total purchase amount of all orders. Return total purchase amount.
Query: SELECT SUM(purch_amt) FROM orders;
Output:
2. To calculate the average purchase amount of all orders. Return average purchase
amount.
Query: SELECT AVG(purch_amt) FROM orders;
Name: Nidhi Bhutna
Section: CST (Roll no. 25)
University Roll No.: 2019723
Output:
3. That counts the number of unique salespeople. Return number of salespeople.
Query: SELECT COUNT (DISTINCT salesman_id) FROM orders;
Output:
4. To find the maximum purchase amount.
Query: SELECT MAX (purch_amt) FROM orders;
Output:
5. To find the minimum purchase amount.
Query: SELECT MIN (purch_amt) FROM orders;
Name: Nidhi Bhutna
Section: CST (Roll no. 25)
University Roll No.: 2019723
Output:
6. To find the highest purchase amount ordered by each customer. Return customer ID,
maximum purchase amount.
Query: Select customer_id MAX (purch_amt) FROM orders GROUP BY customer_id;
Output:
7. To find the highest purchase amount ordered by each customer on a particular date.
Return, order date and highest purchase amount.
Query: Select customer_id, ord_date, MAX (purch_amt) From orders GROUP BY
customer_id, ord_date;
Output:
Name: Nidhi Bhutna
Section: CST (Roll no. 25)
University Roll No.: 2019723
8. To determine the highest purchase amount made by each salesperson on '17-AUG-
2012'. Return salesperson ID, purchase amount .
Query: SELECT salesman_id, MAX (purch_amt) FROM orders
WHERE ord_date = ’17-AUG-2012’
GROUP BY salesman_id;
Output:
9. 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.
Query: SELECT customer_id, ord_date, MAX(purch_amt) FROM orders
GROUP BY customer_id, ord_date
HAVING MAX (purch_amt > 2000.0);
Output: