0% found this document useful (0 votes)
3 views

dbms2ass1

This document outlines a practical assignment for a Database Management System (DBMS) course, focusing on aggregate functions, GROUP BY, and HAVING clauses. It includes SQL queries related to three tables: Order-details, customer_details, and SALESMAN_details, with tasks such as calculating total and average purchase amounts, counting unique salespeople, and finding maximum and minimum purchase amounts. Additionally, it covers customer-related queries, including finding the highest grades by city and counting customers based on specific criteria.

Uploaded by

megh94001
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)
3 views

dbms2ass1

This document outlines a practical assignment for a Database Management System (DBMS) course, focusing on aggregate functions, GROUP BY, and HAVING clauses. It includes SQL queries related to three tables: Order-details, customer_details, and SALESMAN_details, with tasks such as calculating total and average purchase amounts, counting unique salespeople, and finding maximum and minimum purchase amounts. Additionally, it covers customer-related queries, including finding the highest grades by city and counting customers based on specific criteria.

Uploaded by

megh94001
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/ 5

Subject:- DBMS-2

FY CS / IT Sem - 2
PRACTICAL ASSIGNMENT - 1

AIM: AGGREGATE FUNCTIONS ,GROUP BY, HAVING CLAUSE

1) Table-name: Order-details

ord_no Purch_amt ord_date cust_id sales_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-9-10 3005 5002
70005 2400.6 2012-7-27 3007 5001
70008 5760 2012-9-10 3002 5001
70010 1983.43 2012-10-10 3004 5006
70003 2180.4 2012-10-10 3009 5003
70012 250.45 2012-6-27 3008 5002
70011 75.29 2012-8-17 3003 5007
70013 3045.6 2012-4-25 3002 5001
1. write a SQL query to calculate the total purchase amount of all orders.
Display total purchase amount.
2. write a SQL query to calculate the average purchase amount of all
orders. Display average purchase amount.
3. write a SQL query to count the number of unique salespeople.
Display number of salespeople.
4. write a SQL query to find the maximum purchase amount.
5. write a SQL query to find the minimum purchase amount.
6. write a SQL query to count all the orders generated on '2012-08-17'.
Display number of orders.

7. Write a sql query to Count Total Number of Orders.

8. Write a sql query to Find the First and Last Order Dates.

(Hint:-minimum,maximum function)

2) Table-name: customer_details

(Hint:-groupby,aggregate function)

customer_id cust_name city grade salesman_i


d
3002 Nick rim newyork 100 5001
3007 Brad davis New york 200 5001
3005 Graham california 200 5002
zusi
3008 julian london 300 5002
3004 Fabian paris 300 5006
3009 geoff berlin 100 5003
3003 jozy moscow 200 5007
3001 Brad london 5005
1. write a SQL query to find the highest grade of the customers for each
of the city. Display city, maximum grade.
2. write a SQL query to count the number of customers. Display
number of customers.

3. write a SQL query to find the number of customers who got at least a
gradation for his/her activity.
4. write a SQL query to find the highest grade of the customers for each
of the city. Display city, maximum grade.
5.Find the Average Grade of Customers by City
6.Count of Cities with Customers Who Have a Grade more then 200

7.Total Number of Unique Cities Represented by Customers

8.Calculate the Sum of Grades for Each Salesperson:

9.Find Top 2 records from customer details.


10.Find Top 5 records from customer Tables as customer
name in descending order.

3) Table-name: SALESMAN_details

salesman_id | name | city | commission


-------------+------------+----------+------------
5001 | James Hoog | New York | 0.15
5002 | Nail Knite | Paris | 0.13
5005 | Pit Alex | London | 0.11
5006 | Mc Lyon | Paris | 0.14
5007 | Paul Adam | Rome | 0.13
5003 | Lauson Hen | San Jose | 0.12
Queries: (Use any table from above to solve following queries)
1. write a SQL query to count the number of orders by the combination
of each order date and salesperson. Display order date, salesperson
id
2. write a SQL query to find the highest purchase amount ordered by
each customer on a particular date. Display , order date and highest
purchase amount.
3. write a SQL query to find the highest purchase amount on '2012-08-
17' by each salesperson. Display salesperson ID, purchase amount.

4. write a SQL query to find highest order (purchase) amount by each


customer in a particular order date. Filter the result by highest order
(purchase) amount above 2000.00. Display customer id, order date
and maximum purchase amount.
5. write a SQL query to find the maximum order (purchase) amount by
each customer. The customer ID should be in the range 3002 and
3007(Begin and end values are included.). Display customer id and
maximum purchase amount.

You might also like