Lab4-Sql: Using Database "Productorders" As Following
Lab4-Sql: Using Database "Productorders" As Following
1. Find OrderID, Date, CustomerID, CustomerName, Address, Phone, Email of all orders.
2. List all orders of all customers including CustomerID, CustomerName, OrderID, Date. Order the
result by descending order of CustomerName (Note that we need to know also the customer who
have no order). Try to use left outer join for this question.
3. Same as Question 2 but using right outer join for this exercise.
4. List CustomerID of all customers who have never bought any product.
5. Do the intersect between the list of CutomerID from Customers and the list of CustomerID from
Orders? How many rows in the output?
6. Do the union between the list of CutomerID from Customers and the list of CustomerID from
Orders? How many rows in the output?
7. Do the union all between the list of CutomerID from Customers and the list of CustomerID from
Orders? How many rows in the output?
8. List all orders of ‘NGUYEN THI BE’ and ‘LE VAN SANG’, including CustomerID, CustomerName,
OrderID, Date; ordered by CustomerName.
9. List OrderID, ProductCode, ProductName, Price, SellPrice, SoldQuantity, Profit ((SellPrice -
Price)*SoldQuantity) by ascending order of OrderID.
10. List CustomerID, CustomerName, OrderID, ProductCode, ProductName, Price, SellPrice,
SoldQuantity, Profit ((SellPrice - Price)*SoldQuantity) by ascending order of CustomerName.
11. List 5 OrderItems having the highest profit (profit = (SellPrice - Price)*SoldQuantity).
12. List all products (ProductCode, ProductName) bought by both ‘NGUYEN THI BE’ and ‘MAI THI QUE
ANH’.
13. List all products with highest price (Note that there could have many products with the highest
price). You should not use the aggregate function max().
1. List all products having Price smaller than the price of product ‘P05’
2. List all customers who have made an order by using EXISTS in WHERE clause.
3. List all customers who have never made an order by using NOT EXISTS in WHERE clause
4. List all customers who have made an order by using IN in WHERE clause.
5. List all customers who have never made an order by using NOT IN in WHERE clause
7. List all products having Price greater than all the prices of ‘Keyboard’ and ‘Mouse’
8. List all products having price greater than the prices ‘Keyboard’ or ‘Mouse’
9. List all products which have been bought by customer ‘NGUYEN THI BE’ (Nguyễn Thị Bé).
10. List all products having price greater than the average price of all products in Products table.