Exercise 41

100 Exercises — write your own SQL
Exercise 1
List the green items of type C.
Exercise 2
Find the names of green items sold by the Recreation department.
Exercise 3
Of those items delivered, find the items not delivered to the Books department.
Exercise 4
Find the departments that have never sold a geopositioning system.
Exercise 5
Find the departments that have sold compasses and at least two other items.
Exercise 6
Find the departments that sell at least four items.
Exercise 7
Find the employees who are in a different department from their manager's department.
Exercise 8
Find the employees whose salary is less than half that of their manager's.
Exercise 9
Find the green items sold by no department on the second floor.
Exercise 10
Find the items delivered by all suppliers.
Exercise 11
Find the items delivered by at least two suppliers.
Exercise 12
Find the items not delivered by Nepalese Corp.
Exercise 13
Find the items sold by at least two departments.
Exercise 14
Find the items delivered for which there have been no sales.
Exercise 15
Find the items delivered to all departments except Administration.
Exercise 16
Find the name of the highest-paid employee in the Marketing department.
Exercise 17
Find the names of employees who make 10 percent less than the average salary.
Exercise 18
Find the names of employees with a salary greater than the minimum salary paid to a manager.
Exercise 19
Find the names of suppliers that do not supply compasses or geopositioning systems.
Exercise 20
Find the number of employees with a salary under $10,000.
Exercise 21
Find the number of items of type A sold by the departments on the third floor.
Exercise 22
Find the number of units sold of each item.
Exercise 23
Find the green items delivered by all suppliers.
Exercise 24
Find the supplier that delivers no more than one item.
Exercise 25
Find the suppliers that deliver to all departments.
Exercise 26
Find the suppliers that deliver to all the departments that also receive deliveries from supplier 102.
Exercise 27
Find the suppliers that have never delivered a compass.
Exercise 28
Find the type A items delivered by São Paulo Manufacturing.
Exercise 29
Find, for each department, its floor and the average salary in the department.
Exercise 30
If Nancy's boss has a boss, who is it?
Exercise 31
List each employee and the difference between his or her salary and the average salary of his or her department.
Exercise 32
List the departments on the second floor that contain more than one employee.
Exercise 33
List the departments on the second floor.
Exercise 34
List the names of employees who earn more than the average salary of employees in the Shoe department.
Exercise 35
List the names of items delivered by each supplier. Arrange the report by supplier name, and within supplier name, list the items in alphabetical order.
Exercise 36
List the names of managers who supervise only one person.
Exercise 37
List the number of employees in each department.
Exercise 38
List the green items delivered by exactly one supplier.
Exercise 39
Whom does Todd manage?
Exercise 40
List the departments that have not sold all green items.
Exercise 41
Find the first name of Sophie's boss.
Exercise 42
Find the names of employees who make less than half their manager's salary.
Exercise 43
List the names of each manager and their employees arranged by manager's name and employee's name within manager.
Exercise 44
Who earns the lowest salary?
Exercise 45
List the names of employees who earn less than the minimum salary of the Marketing department.
Exercise 46
List the items sold by every department to which all brown items have been delivered.
Exercise 47
List the department and the item where the department is the only seller of that item.
Exercise 48
List the brown items sold by the Books department and delivered by All Seasons.
Exercise 49
Which department has the highest average salary?
Exercise 50
List the supplier that delivers all and only brown items.
Exercise 51
Find the names of items that have never been sold by any department.
Exercise 52
Find the names of items that are sold by at least one department but delivered by no supplier.
Exercise 53
Find items that appear in qdel but not in qsale — delivered items with no recorded sales.
Exercise 54
List all departments that have no employees. Order by floor, then by department name.
Exercise 55
List each floor and the total number of distinct items sold by departments on that floor.
Exercise 56
Find the departments on floor 3 where the total quantity sold (sum of saleqty) exceeds 30.
Exercise 57
List all items sold by at least one department on floor 3.
Exercise 58
List employees who earn more than the overall average salary across all employees.
Exercise 59
Find the departments where every employee earns $35,000 or less.
Exercise 60
List each employee's name, their manager's name, and both salaries.
Exercise 61
Find the employees who are managed by someone in a different department.
Exercise 62
List the name and salary of Todd's direct reports.
Exercise 63
Find the minimum and maximum salary in each department.
Exercise 64
Find the salary range (max minus min) within each department.
Exercise 65
List employees who earn more than every employee in the Accounting department.
Exercise 66
Find the second-highest salary among all employees.
Exercise 67
List each manager together with the count of their direct reports.
Exercise 68
Find the departments where more than two employees report to the same manager.
Exercise 69
List the names of employees who earn more than their own department's average but less than the company-wide average.
Exercise 70
Find the total salary cost per floor.
Exercise 71
Find the items delivered by Nepalese Corp. but not by All Seasons.
Exercise 72
Find the suppliers that deliver at least one item of both type A and type B.
Exercise 73
Find the suppliers that deliver to at least four distinct departments.
Exercise 74
Find the items delivered by exactly two distinct suppliers.
Exercise 75
Find items delivered to floor-2 departments that are not sold by those departments.
Exercise 76
Find the item with the highest total delivery quantity across all suppliers and departments.
Exercise 77
Find items whose total delivered quantity across all records exceeds 100.
Exercise 78
Find the supplier that delivers the most distinct items.
Exercise 79
List the suppliers that deliver to at least two distinct departments on floor 3.
Exercise 80
Find the average delivery quantity per department for each supplier.
Exercise 81
Find items that are sold by all departments that sell any type-C item.
Exercise 82
Find the suppliers that deliver Boots to all three floor-3 departments (Clothes, Equipment, Shoe).
Exercise 83
List the departments that receive deliveries from every supplier that delivers a type-N item.
Exercise 84
For each item, list its type, its color, the departments that sell it, and those departments' floor numbers.
Exercise 85
List all supplier-department pairs where the supplier delivers at least one item to the department that the department also sells.
Exercise 86
Find departments that both sell and receive deliveries of Compass.
Exercise 87
List items sold by the Navigation department that are also of type N.
Exercise 88
List pairs of employees who work in the same department (report each pair once, A before B alphabetically).
Exercise 89
List pairs of departments located on the same floor.
Exercise 90
Find employees who share the same manager as Nancy.
Exercise 91
List each item type and the count of distinct items of that type.
Exercise 92
List each item color and the total quantity sold of items of that color.
Exercise 93
Find the department that recorded the highest total sales quantity (sum of all saleqty).
Exercise 94
List each supplier and the total number of distinct departments it delivers to.
Exercise 95
Find the item that appears in the most supplier-department delivery combinations (most qdel rows).
Exercise 96
Is it true that every item sold by the Shoe department is also sold by at least one other department? Produce a single True/False result.
Exercise 97
Is it true that no floor-1 department has any recorded sales? Produce a single True/False result.
Exercise 98
Find items that are the same color as Compass but a different type.
Exercise 99
Find the departments that sell every item of type B.
Exercise 100
List each employee together with the full chain of management above them (employee → manager → manager's manager), stopping at the top.

Playbook Schema

qdept deptnamedeptfloor 12 rows
qemp empnoempfnameempsalarydeptnamebossno 13 rows
qitem itemnameitemtypeitemcolor 14 rows
qspl splnosplname 6 rows
qsale deptnameitemnamesaleqty 26 rows
qdel splnoitemnamedeptnamedelqty 46 rows
Exercise 41
Find the first name of Sophie's boss.
SELECT only — playbook
Write your SQL above and click Run Query.