You are on page 1of 2

Structured Query Language

Sample Database Schema


Customers (cid, name, address, city, country, phone, fax)
Orders (oid, odate, requiredDate, shippedDate, cid, empId, shipName)
Orderdetails (oid, pid, qty, price, discount)
Products (pid, pname, category id, unit price, units in stock, sid)
Suppliers (sid, sname, scity, scountry)

Queries

Basic
1. Get the details of products having unit price greater than 60.
2. What are the names and phone numbers of customers in Berlin or London city?
3. What are the list of products whose name starts with S or T and whose unit price is greater than 30?
4. Show the details of orders whose shipped date is greater than the required date?

Aggregates I
5. How many customers are from London city?
6. What is the average price of items in the Beverages category (category id = 1)?
7. What is the total number of customers in each country?
8. Get the category-wise average price of items, only for items whose average price is above 30?

Aggregates II
9. Find the number of orders executed by each shipper.
10. Which of the employees have executed more than 60 orders? Sort the results in descending order.
11. Which shipper has executed/shipped the maximum number of orders?

Joins
12. Show the details of all customers who have placed an order.
13. Get the order details (oid, odate, empId, shipName) of customers from Spain. Your results should include
all the relevant customers, including those who have not placed any order.
14. Get the details of suppliers who do not supply any products.

Joins + Aggregates
15. Get the total order amount for order number 10251
16. Compute the total order amount for each of the orders placed in the year 1996.
17. What is the total number of orders placed by customer names starting with Ana in 1997?
18. What is the average quantity of products ordered by customers from London?

Advanced: Subquery / Join


19. Get the details of customer name, address and city for those who have not placed any order (use sub query)
20. Get the order details of customers from Mexico
21. Show all order identifiers that include a product from Beverages product category (category id = 1)

Advanced: Join / Exists / Multiple query


22. Get the names of suppliers who do not supply Tofu (product id: 14)
23. Show the Top 5 most valuable customers by order value
24. Show the average purchase frequency, average order value and last purchase date for each customer

You might also like