Loading exercise…
Loading exercise…
Exercises are built for a keyboard. Read the task here, then open this page on a laptop to solve it.
WHERE vs HAVING. WHERE filters rows before they are grouped. HAVING filters groups after their totals exist. So a rule about a single row (this line has a discount) goes in WHERE, and a rule about a total (more than 100 units) goes in HAVING, after GROUP BY. One query can use both.
select region_id, count(*) as customers from customers where segment = 'SMB' group by region_id having count(*) > 15
Pricing suspects that some products mostly sell on discount. They want the products whose discounted order lines add up to more than 250 units.
Using only order lines with a discount (discount_pct above 0), return product_id and discounted_units (the sum of quantity) for the products where that total is over 250.
Loading the Brightline dataset…
Language
Full plan
SQL ✓ · Excel and Power BI also included
Cancel anytime · 14-day full refund · Secure payment by Stripe