Northwind Queries and Activities

You might also like

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

Exploring the Tables

SELECTing Specific Columns

Duration: 5 to 15 minutes.
In this exercise, you will practice selecting specific columns from tables in the Northwind
database.

1. Select CategoryName and Description from the Categories table.


2. Select ContactName, CompanyName, ContactTitle and Phone from
the Customers table.
3. Select EmployeeID, Title, FirstName, LastName, and Region from
the Employees table.
4. Select CompanyName, Fax, Phone and HomePage from the Suppliers table.

Sorting Results

Duration: 5 to 15 minutes.
In this exercise, you will practice sorting results in SELECT statements.

1. Select CategoryName and Description from the Categories table sorted


by CategoryName.
2. Select ContactName, CompanyName, ContactTitle, and Phone from
the Customers table sorted by Phone.

Using the WHERE clause to check for equality or inequality

Duration: 5 to 15 minutes.
In this exercise, you will practice using the WHERE clause to check for equality and
inequality.

1. Create a report showing all the company names and contact names of
Northwind's customers in Buenos Aires.
2. Create a report showing the product name, unit price and quantity per unit of all
products that are out of stock.
3. Create a report showing the order date, shipped date, customer id, and freight of
all orders placed on May 19, 1997.
o MySQL users will have to use following date format: 'yyyy-mm-
dd' (e.g, '1997-05-19').
4. Create a report showing the first name, last name, and country of all employees
not in the United States.

1
Using the WHERE clause to check for greater or less than

Duration: 5 to 15 minutes.
In this exercise, you will practice using the WHERE clause to check for values greater
than or less than a specified value.

1. Create a report that shows the employee id, order id, customer id, order date,
and shipped date of all orders that were shipped later than they were ordered.
2. Create a report that shows all orders that have a freight cost of more than
$500.00.
3. Create a report that shows the product name, units in stock, units on order, and
reorder level of all products that are up for reorder.

Checking for NULL

Duration: 5 to 15 minutes.
In this exercise, you will practice selecting records with fields that have NULL values.

1. Create a report that shows the company name, contact name and fax number of
all customers that have a fax number.
2. Create a report that shows the first and last name of all employees who do not
report to anybody.

Using WHERE and ORDER BY Together

Duration: 5 to 15 minutes.
In this exercise, you will practice writing SELECT statements that use
both WHERE and ORDER BY.

1. Create a report that shows the company name, contact name and fax number of
all customers that have a fax number. Sort by company name.
2. Create a report that shows the city, company name, and contact name of all
customers who are in cities that begin with "A" or "B." Sort by contact name in
descending order.

2
More SELECTs with WHERE

Duration: 5 to 15 minutes.
In this exercise, you will practice writing SELECT statements that use WHERE with
word operators.

1. Create a report that shows the first and last names and birth date of all
employees born in the 1950s.
2. Create a report that shows the product name and supplier id for all products
supplied by Exotic Liquids, Grandma Kelly's Homestead, and Tokyo
Traders. Hint: you will need to first do a separate SELECT on the Suppliers table
to find the supplier ids of these three companies.
3. Create a report that shows the shipping postal code, order id, and order date for
all orders with a ship postal code beginning with "02389".
4. Create a report that shows the contact name and title and the company name for
all customers whose contact title does not contain the word "Sales".

Writing SELECTs with Multiple Conditions

Duration: 5 to 15 minutes.
In this exercise, you will practice writing SELECT statements that filter records based on
multiple conditions.

1. Create a report that shows the first and last names and cities of employees from
cities other than Seattle in the state of Washington.
2. Create a report that shows the company name, contact title, city and country of
all customers in Mexico or in any city in Spain except Madrid.
3. Create a report showing the first and last name of all sales representatives whos
e title of courtesy is "Mr."
4. Create a report showing the first and last name and the city of all employees who
are from Seattle or Redmond.
5. Create a report showing the first and last name of all sales representatives who a
re from Seattle or Redmond.

3
Calculating Fields

Duration: 10 to 20 minutes.
In this exercise, you will practice writing SELECT statements with calculated fields.

1. Create a report that shows the unit price, quantity, discount, and the calculated
total price using these three fields.
2. Write a SELECT statement that outputs the following.

4
Working with Aggregate Functions

Duration: 10 to 20 minutes.
In this exercise, you will practice working with aggregate functions. For all of these
questions, it's okay if your result set's rows are in a different order.

1. Create a report that returns the following from the Order_Details table.

The report should only return rows for which TotalUnits is less than 200.

2. Create a report that returns the following from the Products table.

The report should only return rows for which the average unit price of a product is
greater than 70.

3. Create a report that returns the following from the Orders table.

5
NumOrders represents the number of orders placed by a certain customer. Only
return rows where NumOrders is greater than 15.

4. Find the Number of Employees

5. Find the Total Number of Units Ordered of Product ID 3


6. Find the Average Unit Price of Products
7. Find the Earliest and Latest Dates of Hire
8. Retrieve the number of employees in each city
9. Retrieve the number of employees in each city in which there are at least 2 empl
oyees.
10. Find the number of sales representatives in each city that contains at least 2 sal
es representatives. Order by the number of employees.

Query number 2 above has something strange about it. It is, in fact, a ridiculous query.
Why? Try to get the exact same results without using an aggregate function.

6
Using Joins

Duration: 25 to 40 minutes.
In this exercise, you will practice using joins.

1. Create a report showing employee orders.


2. Create a report showing the Order ID, the name of the company tha
t placed the order, and the first and last name of the associated
employee. Only show orders placed after January 1, 1998 that ship
ped after they were required. Sort by Company Name.

3. Create a report that shows the order ids and the associated employee names for
orders that shipped after the required date. It should return the following.

There should be 37 rows returned.

7
4. Create a report that shows the total quantity of products (from
the Order_Details table) ordered. Only show records for products for which the
quantity ordered is fewer than 200. The report should return the following 5 rows.

5. Create a report that shows the total number of orders by Customer since
December 31, 1996. The report should only return rows for which the NumOrders
is greater than 15. The report should return the following 5 rows.

6. Create a report that shows the company name, order id, and total price of all
products of which Northwind has sold more than $10,000 worth. There is no
need for a GROUP BY clause in this report.

You might also like