CECS323 Classic Models Practice SQL
CECS323 Classic Models Practice SQL
16. List all products not supplied by ‘Highway 66 Mini Classics’ order by productName (101)
Natural Join
Set Operations
37. List all customers who didn't order in 2015 (78)
38. List all people that we deal with (employees and customer contacts). Display contact first
name, contact last name, company name for the customers. For the employees, display
their first name, last name, and just the literal ‘Employee’ for the employees. Returns
145 rows.
39. List the last name, first name, and employee number of all of the employees who do not
have any customers. Order by last name first, then the first name. (8).
40. List the states and the country that the state is part of that have customers but not
offices, offices but not customers, or both one or more customers and one or more
offices all in one query. Designate which state is which with the string 'Customer',
'Office', or 'Both'. If a state falls into the “Both” category, do not list it as a Customer or
an Office state. Order by the country, then the state. Give the category column (where
you list ‘Customer’, ‘Office’, or ‘Both’) a header of “Category” and exclude any entries in
which the state is null. (19)
41. List the Product Code and Product name of every product that has never been in an
order in which the customer asked for more than 48 of them. Order by the Product
Name. (8)
42. List the customer name of any customer who ordered any products from either of the
two product lines ‘Trains’ or ‘Trucks and Buses’. Do not use an “or”. Instead perform a
union. Order by the customer’s name. (61)
43. List the name of all customers who do not live in the same state and country with any
other customer. Do not use a count for this exercise. Order by the customer name.
This returns 17 if you convert the null states to something like ‘N/A’ and it returns 10 if
you exclude all customers with no state value at all.
Subqueries
44. What product that makes us the most money (qty*price) across all orders for that
product? Returns 1.
54. List all the customers who have never made a payment on the same date as another
customer. Order by customer name. (57)
55. Find customers who have ordered the same thing. For instance, if ‘AV Stores, Co.’
orders a particular item five times, and ‘Land of Toys Inc.’ orders that same item 4 times,
it only counts as one item that they have ordered in common. Find only those customer
pairs who have ordered more than 40 different items in common (3).
56. What is the manager who manages the greatest number of employees (2)
57. Select all employees and their manager who work for the manager that manages the
greatest number of employee (12)
61. Find all of the customers who have the same sales representative as some other
customer, and either customer name has ‘Australian’ in it. List each of the customers
sharing a sales representative, and the name of the sales representative. Order by the
name of the first customer, then the second. Do not show any combination more than
once. (9)