CS403P Assignment

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 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 Atif@vu.edu.pk
C003 Dr. Tooba Khan H#15 street 3 Multan Punjab 87000 Tooba@vu.edu.pk
C004 Dr. Asma Malik H#50 street 2 Lahore Punjab 90000 Asma@vu.edu.pk
C005 Dr. Shahid Naeem H#10 street 1 Karachi Sindh 88500 Shahid@vu.edu.pk
C006 Mr. Raza Ch H#05 street 2 Peshawar KPK 57800 Raza@vu.edu.pk

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