Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Part 1 (3 marks) Open the hosted north wind database hosted at

● https://www.w3schools.com/sql/trysql.asp?filename=trysql
Execute the SQL statements below and observe the result. Try to guess what each SQL
statement does and explain it . Also mention how many records each SQL statement
generates

Q1 SELECT * FROM [Customers]

This SQL statement is going into the database and collecting all the data information
from the ‘’Customers” table and showing it in a single table. This table shows all the
information we have about customers. There are 91 records.

Q2 SELECT Country FROM Customers

This SQL statement is only going to list out the name of every country that each
customer is from. There will be one country for every customer, regardless of if there
are multiple customers from the same country. There are 91 records.
Q3 SELECT DISTINCT(Country) FROM Customers

This SQL statement is going to list the different country names once. However, if
there are multiple customers form the same country then that country will only be
listed once. There are 21 records.
Q4 SELECT COUNT(CustomerID), Country
FROM Customers
GROUP BY Country

This SQL statement is going to list out all the different countries that customers are
from in one column and in another column there will be the total number of customers
that are from that given country. There are 21 records.

Q5 SELECT Country, COUNT(CustomerID) as numberOfCustomers


FROM Customers
GROUP BY Country
ORDER BY numberOfCustomers

This SQL statement is trying to list out all the different countries that customers are
from in one column and in another column there will be the total number of customers
that are from that given country. Additionally it is trying to list the data by the number
of customers in ascending order. However, there is an error in this statement and
therefore 0 records shown.
Q6 SELECT * FROM Customers, Orders

WHERE Customers.CustomerID = Orders.CustomerID

This SQL statement shows all the customer information for every order in the
database. There are 196 records.
Part 2 (7 marks)
Consider the Northwind sample database posted available at
https://www.w3schools.com/sql/trysql.asp?filename=trysql_select_all
(Links to an external site.)
Write the following Queries:

Q7 (1 mark) List all cities from the customer table (we want to know what cities are there in
the customer table). How many cities are there?

SELECT distinct country, city


FROM Customers;
There are 69 cities.

Q8 (1 mark) List the customers who are from Germany but not from city Brandenburg

SELECT CustomerName, Country, City


FROM customers
WHERE Country = 'Germany'
AND City <> 'Brandenburg';
There are 10 records.
Q9 (1 mark) List all the products whose price is more than 10 but less than or equal to 20
(display the result in descending order (based on the product price)

SELECT ProductName, Price


FROM Products
WHERE Price > 10 AND Price <= 20
ORDER BY Price DESC;
There are 26 records.

Q10 (2 marks) List all the product names which are ordered for quantity of more than 10. The
result set (resulting table) has to include the following column (Note: just list unique product
names . That means do not repeat a product name multiple times) ProductName, Quantity

SELECT DISTINCT ProductName


FROM Products, OrderDetails
WHERE OrderDetails.ProductID = Products.ProductID
AND OrderDetails.Quantity > 10;
There are 76 records.

Q11 (2 marks) List all the product names which are ordered for quantity of more than 10 by
customers from USA the result set has to include the following columns CustomerName,
ProductName, Quantity
SELECT CustomerName, ProductName, Quantity
FROM OrderDetails, Products, Customers
WHERE OrderDetails.ProductID = Products.ProductID
AND Quantity > 10
AND Country = 'USA';
There are 5018 records.

You might also like