Skip to content

ARSB week-over-week receiving yards

Level 3 · Challenge 3
Starter

Prompt

For Amon-Ra St. Brown in the 2024 regular season, return week, receiving yards, previous week’s receiving yards, and the week-over-week delta. Sort by week. Week 1’s previous-yards column should be NULL, not 0.

Expected output

weekyardsprev_yardsdelta
Hint

LAG(receiving_yards) OVER (ORDER BY week) for prev. Subtract for delta. No PARTITION BY needed — you’re already filtering to one player.

Solution
SELECT
week,
receiving_yards AS yards,
LAG(receiving_yards) OVER (ORDER BY week) AS prev_yards,
receiving_yards - LAG(receiving_yards) OVER (ORDER BY week) AS delta
FROM weekly_stats
WHERE player_display_name = 'Amon-Ra St. Brown'
AND season = 2024
AND season_type = 'REG'
ORDER BY week;

Week 1 has NULL for both prev_yards and delta because there’s no previous week. That’s correct — passing a default of 0 would make Week 1 look like a big positive delta, which is a lie.