Loading exercise…
Loading exercise…
Exercises are built for a keyboard. Read the task here, then open this page on a laptop to solve it.
Top N per group and QUALIFY. Number the rows inside each group, then keep the first N. In standard SQL you filter the number in an outer query (a WITH block or a subquery). DuckDB also has QUALIFY, a WHERE for window results, written after GROUP BY: QUALIFY ROW_NUMBER() OVER (...) <= N. Both forms give the same rows.
select customer_name, segment, signup_date from customers qualify row_number() over (partition by segment order by signup_date, customer_name) <= 2
The warehouse is setting safety stock and wants the two best-selling products by units in every category.
Return category, product_name and units (total quantity on completed orders) for the two products with the most units in each category. If two products tie on units, the one whose name comes first alphabetically wins.
Loading the Brightline dataset…
Language
Full plan
SQL ✓ · Excel and Power BI also included
Cancel anytime · 14-day full refund · Secure payment by Stripe