0% found this document useful (0 votes)
2 views6 pages

Exercises_SQL

The document outlines a database schema consisting of 8 tables with a total of 932 records, detailing the structure of each table including fields, data types, and constraints. It includes tables for Customers, Categories, Employees, Products, Suppliers, Shippers, Orders, and OrderDetails, each with specific attributes. Additionally, it provides SQL query examples for retrieving data based on various criteria, such as customer location and product categories.

Uploaded by

Thịnh Đặng
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
2 views6 pages

Exercises_SQL

The document outlines a database schema consisting of 8 tables with a total of 932 records, detailing the structure of each table including fields, data types, and constraints. It includes tables for Customers, Categories, Employees, Products, Suppliers, Shippers, Orders, and OrderDetails, each with specific attributes. Additionally, it provides SQL query examples for retrieving data based on various criteria, such as customer location and product categories.

Uploaded by

Thịnh Đặng
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 6

http://www.w3schools.com/sql/trysql.asp?

filename=trysql_select_all
8 tables with 932 records in total
OrderDetails

OrderDetailID
Categories Products
OrderID
CategoryID ProductID Orders ProductID
CategoryID OrderID
SupplierID CustomerID
Employees
EmployeeID
EmployeeID
ShipperID

Suppliers

SupplierID
Customers Shippers

CustomerID ShipperID

1. Customers table
No. Field name Field type NOT NULL Unique
1. CustomerID Integer x x

2. CustomerName String x

3. ContactName String x

4. Address String

5. City String

6. PostalCode String x

7. Country String

1
2. Categories table
No. Field name Field type NOT NULL Unique
1. CategoryID Integer x x
2. CategoryName String x

3. Description String

3. Employees table
No. Field name Field type NOT NULL Unique
1. EmployeeID Integer x x

2. LastName String x

3. FirstName String x

4. Birthdate Date x

5. Photo String

6. Note String

2
4. Products table
No. Field name Field type NOT NULL Unique
1. ProductID Integer x x
2. ProductName String x

3. SupplierID Integer x

4. CategoryID Integer x

5. Unit String

6. Price Double x

5. Suppliers table
No. Field name Field type NOT NULL Unique
1. SupplierID Integer x x

2. SupplierName String x

3. ContactName String x

4. Address String x

5. City String

6. PostalCode String x

7. Country String

8. Phone String

3
6. Shippers table
No. Field name Field type NOT NULL Unique
1. ShipperID Integer x x
2. ShipperName String x

3. Phone String x

7. Orders table
No. Field name Field type NOT NULL Unique
1. OrderID Integer x x

2. CustomerID Integer x

3. EmployeeID Integer x

4. OrderDate DateTime x

5. ShipperID Integer x

4
8. OrderDetails table
No. Field name Field type NOT NULL Unique
1. OrderDetailID Integer x x
2. OrderID Integer x

3. ProductID Integer x

4. Quantity Integer x

Write queries in SQL


1. Provide a list of customers in London (city).
2. Provide a list of products in the "seafood" category (categoryName).
3. Provide a list of products supplied by the supplier with ID "X".
4. Provide a list of orders in December 1996 shipped by the supplier "Speedy Express." The
information should include customerID, customerName, Country, OrderDate, and the
order value, calculated as the total value of the products in the order.
5. Provide a list of products with the highest order quantities.
6. Provide a list of products with the highest revenue.
7. Provide a list of products that have never been ordered.
8. Provide a list of employees and the total revenue of the orders they managed.
9. Provide a list of products without any order
10. Provide a list of product categories (Categories) and the number of products in each
category.
11. Provide a list of customers who placed over five orders in 1996.
12. Provide the number of products in each category supplied by each supplier.

10

5
SELECT * FROM Customers;
WHERE City = 'London’;

SELECT * FROM Customers WHERE City LIKE '%London%';

SELECT * FROM Categories


WHERE CategoryName = 'sea food’

SELECT Product.*
FROM Product, Categories
WHERE Product.categoryid = Categories.categoryid and
CategoryName = ‘seafood’;

select ProductID from Products Where SuppliesID = X


11

• SELECT C.customerID, C.customerName, C.Country, O.OrderDate,


sum(P.Price*OD.Quantity) Value
• FROM Customers C, Orders O, Suppliers S, OrderDetails OD, Products
P
• WHERE C.CustomerID = O.CustomerID and O.OrderID = OD.OrderID
and OD.ProductID = P.ProductID and P.SupplierID = S.SupplierID and
OrderDate like '1996-12-__' and SupplierName = "Pavlova, Ltd."
• Group By C.customerID, C.customerName, C.Country, O.OrderDate

12

You might also like