Loading exercise…
Loading exercise…
Exercises are built for a keyboard. Read the task here, then open this page on a laptop to solve it.
FIRST_VALUE, LAST_VALUE and the frame. FIRST_VALUE(x) and LAST_VALUE(x) return x from the first or the last row of the window's frame. With an ORDER BY, the default frame runs from the start of the group up to the current row only, not to the end of the group. A frame clause (ROWS BETWEEN …) changes which rows the window can see.
select region_id, month, revenue_target, first_value(month) over (partition by region_id order by revenue_target desc) as best_month from targets
You asked the AI assistant to show each product beside the best and the worst seller of its category, for the range review. The worst-seller column just repeats each row's own product.
AI assistant: “I used FIRST_VALUE for the top seller and LAST_VALUE for the bottom seller, both ordered by revenue within each category.”
Run the AI query, then fix it so it returns product_name, category, revenue (completed, 2 decimals), category_leader (the category's highest-revenue product) and category_laggard (the category's lowest-revenue 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