Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
19 views4 pages

SQL Queries for Order Analysis

This document contains an assignment to write SQL queries to analyze data from an orders table. It includes the table structure and 9 questions to write queries for, such as finding the total purchase amount, average purchase amount, highest purchase by customer and date, and highest purchase by salesperson on a given date above $2000. The student provides the SQL query for each question and notes that the output will be returned.

Uploaded by

vectordsaa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views4 pages

SQL Queries for Order Analysis

This document contains an assignment to write SQL queries to analyze data from an orders table. It includes the table structure and 9 questions to write queries for, such as finding the total purchase amount, average purchase amount, highest purchase by customer and date, and highest purchase by salesperson on a given date above $2000. The student provides the SQL query for each question and notes that the output will be returned.

Uploaded by

vectordsaa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

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:

You might also like