Loading exercise…
Loading exercise…
Exercises are built for a keyboard. Read the task here, then open this page on a laptop to solve it.
The FILTER clause. DuckDB lets you attach a condition to any aggregate: COUNT(*) FILTER (WHERE rule) counts only the matching rows, and SUM(x) FILTER (WHERE rule) adds only theirs. It does the same job as SUM(CASE …) and reads more easily. Rows that fail the rule still count in the other columns.
select segment, count(*) as customers, count(*) filter (where signup_date >= '2025-01-01') as new_2025 from customers group by segment
Pricing wants a per-product view of how often discounts are given: all order lines, the discounted ones, and the units sold at full price.
Return product_id, lines (all order lines), discounted_lines (lines with discount_pct above 0) and full_price_units (the sum of quantity on lines with discount_pct 0), one row per product.
Loading the Brightline dataset…
Language
Full plan
SQL ✓ · Excel and Power BI also included
Cancel anytime · 14-day full refund · Secure payment by Stripe