Interview › Year over year

SQL interview: year-over-year with LAG

YoY is MoM with a different lag. Get the grain right first.

Prompt. Annual sales and the prior year’s sales.

Hint: LAG(sales, 1) OVER (ORDER BY yr)

Same month last year: grain to year-month, LAG(..., 12).

Then write it on a ticket

Monday is free. A colleague asks, you type, we mark it.

Clock in free