Name a query step
Use a common table expression to name a result used by the next query.
What you are trying to do
A weekly report needs a readable total before it filters busy days.
Work through it
- Read the CTE definition as a separate result.
- Check the outer query's filter and order.
- Rename one CTE column and update its reference.
Check your work
The CTE returns one row per day and the outer query shows only days above the limit.
Practice SQL
Open in SQL FlowWITH DailyWork AS (SELECT WorkDay, SUM(Units) AS TotalUnits FROM (VALUES (1, 4), (1, 3), (2, 9), (3, 2)) AS Entry(WorkDay, Units) GROUP BY WorkDay) SELECT WorkDay, TotalUnits FROM DailyWork WHERE TotalUnits >= 5 ORDER BY WorkDay;
Commands in this lesson
Next lesson Rank rows inside a group