25% found this document useful (4 votes)
5K views

CS403P Assignment

The document provides an example database schema with Customer, Order, and Shipper tables and asks to write SQL queries to perform various tasks on the tables. Five tasks are listed: 1) retrieve customers whose name starts with "Dr", 2) list number of customers grouped by province, 3) find customer with maximum order price, 4) retrieve order details joining customer and shipper tables, 5) use self join to find customers from same province. SQL queries answering each task are provided.

Uploaded by

Ali Raza Noshair
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
25% found this document useful (4 votes)
5K views

CS403P Assignment

The document provides an example database schema with Customer, Order, and Shipper tables and asks to write SQL queries to perform various tasks on the tables. Five tasks are listed: 1) retrieve customers whose name starts with "Dr", 2) list number of customers grouped by province, 3) find customer with maximum order price, 4) retrieve order details joining customer and shipper tables, 5) use self join to find customers from same province. SQL queries answering each task are provided.

Uploaded by

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

Assignment No.

02
SEMESTER Spring 2022
CS403P- Database Management Systems (Practical)

Question 1: Marks = 10

Consider the following relation and write the SQL commands for the following tasks:

Customer:

CustomerID CustomerName Address City Province OrderPrice Email


C001 Mr. Hussain Alii H#23 street 3 Lahore Punjab 55000 Hussain @vu.edu.pk
C002 Dr. Atif Ali H# 45 street 1 Karachi Sindh 85000 [email protected]
C003 Dr. Tooba Khan H#15 street 3 Multan Punjab 87000 [email protected]
C004 Dr. Asma Malik H#50 street 2 Lahore Punjab 90000 [email protected]
C005 Dr. Shahid Naeem H#10 street 1 Karachi Sindh 88500 [email protected]
C006 Mr. Raza Ch H#05 street 2 Peshawar KPK 57800 [email protected]

Order:

OrderID CustomerID ShipperID OrderDate


A001 C001 S01 7/4/2002
B002 C002 S02 7/4/2002
C003 C001 S03 8/8//2002
D004 C004 S01 7/4/2001
E005 C003 S03 4/4/2001
F006 C006 S02 5/4/2002
Shipper:
ShipperI ShipperName ShipperPhone
D
S01 Express 2345
S02 Lipard 5432
S03 DHL 5643

Solution:

1. Retrieve Customer Name from customer table whose customer name start with like
“Dr”

Solution:

SELECT * FROM Customer
WHERE CustomerName LIKE 'Dr%';

2. Lists the number of customers in each province, sorted high to low.


Solution:

SELECT COUNT(CustomerID), Province
FROM Customers
GROUP BY Province
ORDER BY COUNT(CustomerID) DESC;

3. Write SQL query to display Customer name whose order size is maximum.

Solution:

SELECT customer_id, CustomerName, MAX(OrderPrice)


FROM customer
GROUP BY customer_id;

4. Retrieve orders Id,Customer Name,Shipper name with customer and shipper


information
Solution:

SELECT Orders.OrderID, Customers.CustomerName, Shippers.ShipperName


FROM ((Orders
INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID)
INNER JOIN Shippers ON Orders.ShipperID = Shippers.ShipperID);

5. Using self join write SQL statement matches customer that are from the same
province.
Solution:

SELECT A.CustomerName AS CustomerName1,
B.CustomerName AS CustomerName2, A.Province
FROM Customers A, Customers B
WHERE A.CustomerID <> B.CustomerID
AND A.Province = B.Province
ORDER BY A.Province;

You might also like