Loading exercise…
Loading exercise…
Exercises are built for a keyboard. Read the task here, then open this page on a laptop to solve it.
Streaks: gaps and islands. List the distinct periods per customer, then subtract ROW_NUMBER() from the period number. Inside an unbroken run both rise by one, so the difference stays the same; a gap changes it. Group by customer and that difference to get each run (an island), COUNT(*) its length, and take the MAX per customer.
with m as ( select distinct region_id, month(month) as m from targets where revenue_target > 9000 ) select region_id, m, m - row_number() over (partition by region_id order by m) as island from m
The loyalty team wants to reward steady buyers: customers who placed a completed order in many months in a row.
For each customer, find the longest run of consecutive months (2025) with at least one completed order. Return customer_name and longest_streak for every customer whose longest run is 7 months or more.
Loading the Brightline dataset…
Language
Full plan
SQL ✓ · Excel and Power BI also included
Cancel anytime · 14-day full refund · Secure payment by Stripe