Interview › Month over month

SQL interview: month-over-month growth

Two grains: first the month, then the previous month. Do not LAG the raw orders.

Prompt. Sales by month, previous month, and percent change.

Hint: LAG(sales) OVER (ORDER BY ym)

First month’s LAG is NULL. NULLIF stops a divide by zero.

Then write it on a ticket

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

Clock in free