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
| week | yards | prev_yards | delta |
|---|
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 deltaFROM weekly_statsWHERE 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.