Loading exercise…
Loading exercise…
Exercises are built for a keyboard. Read the task here, then open this page on a laptop to solve it.
LEAD() and gaps between rows. LEAD(x) OVER (PARTITION BY g ORDER BY y) brings the next row's x onto the current row, within each group. date_diff('day', a, b) then gives the days in between. The last row of each group has no next row, so its gap is NULL, and MAX ignores it.
select region_id, month, revenue_target, lead(revenue_target) over (partition by region_id order by month) as next_target from targets
Account managers suspect some Enterprise customers buy in bursts. They want each Enterprise customer's longest wait between two completed orders in 2025.
Return customer_name and longest_gap_days (the most days between one completed order and that customer's next completed order) for each Enterprise customer.
Loading the Brightline dataset…
Language
Full plan
SQL ✓ · Excel and Power BI also included
Cancel anytime · 14-day full refund · Secure payment by Stripe