SQL practice: CTEs: Naming Your Steps
Chapter 18 · 10 questions · included in full access
Question 1 · easy
Solve it in your browserUse a CTE to find the top 3 customers by total spend.
Question 2 · easy
Solve it in your browserUse a CTE for total quantity sold per product, then show only products above 150.
Question 3 · medium
Solve it in your browserUse a CTE to calculate revenue per branch, then show only branches above the average branch revenue.
Question 4 · medium
Solve it in your browserUse a CTE to count orders per customer, then show only customers with more than 2.
Question 5 · medium
Solve it in your browserChain two CTEs: one for revenue per product, one that adds a rank, then show the top 5.
Question 6 · medium
Solve it in your browserUse a CTE to work out each employee's total handled revenue, then join it to employees to show names.
Question 7 · medium
Solve it in your browserUse a CTE for total spend per customer, then show the overall average of those totals.
Question 8 · medium
Solve it in your browserRewrite this nested query as a CTE: SELECT * FROM (SELECT role, AVG(salary) AS avg_pay FROM employees GROUP BY role) t WHERE avg_pay > 45000;
Question 9 · hard
Solve it in your browserChain three CTEs: revenue per branch → add a rank → join to branch names, showing only the bottom 3.
Question 10 · hard
Solve it in your browserFind customers whose total spend is above the average customer's spend. It fails with 'relation "customer_totals" does not exist'. Fix it.
These questions are part of full access.
The first chapters of every track are free. Full access is a one-time payment.
See pricing