In this workshop you'll learn how to consult, filter, aggregate, join, order and project data coming from the relational database called Xtreme
by using the following statements:
SELECT
DISTINCT
WHERE
ORDER BY
GROUP BY
[INNER|LEFT|OUTER] JOIN
- SQL Server 2017+ Installed;
- SQL Server Management Studio Installed;
- A running copy of the database xtreme.
You can download the database by using this link, information on how to restore a database can be found here.
Below you'll find multiple exercises, for each exercise do the following:
- Investigate the database schema of the xtreme database;
- Figure out which:
- table(s) you will be consulting;
- columns you will be projecting;
- filters that are needed;
- aggregations that are mandatory;
- sort order is necessary.
- Write the query;
- Check your results.
- Give the unique names of all products containing the word 'helmet' or with a name of 6 characters.
- Show the name and the reorderlevel of all products with a level between 50 and 500 (boundaries included)
- Count the amount of products, give the column the following name "Amount of Products". In a second column, count the amount of products where the unit in stock is known. Give the second column a descriptive column name.
- How many unique supervisors are there?
Hint: Count all the unique people who are supervising others;
- Give the date of birth of the youngest employee and the oldest.
- What’s the number of employees who will retire (at 65) within the first 30 years?
- Show a list of different countries where 2 of more suppliers live in, make sure to order alphabeticaly.
- Which suppliers offer at least 10 products with a price less then 100 dollar? Show supplierIdand the number of different products. The supplier with the highest number of products comes first.
- Count the number of workers (salary below 40.000), clerks (salary between 40.000 and 50.000 EUR) and managers (salary > 50000). Show 2 columns the name of the role and the amount of people in that role.
- Which suppliers (Id and name) deliver products from the class "Bicycle"?
- Give for each supplier the number of orders that contain products of that supplier. Show supplierID, supplier name and the number of orders. Order the results alphabetically by the name of the supplier.
- What’s for each type the lowest productpriceof products for Youth? Show producttypename and lowest.
Hint: products for youth contain
Y
in theM_F
field - Give for each purchased productId: productname, the least and the most ordered. Order by productname.
- Give a summary for each employee with orderID, employeeIDand employeename.
Make sure that the list also contains employees who don’t have orders yet.
- Is the
LIKE
operator case-sensitive or not? - Why is it not possible to use certain columns from the
SELECT
statement in theWHERE
,ORDER BY
orGROUP BY
clauses?
A possible solution for these exercises can be found here.