Prompt
NFL running backs in the 2024 regular season with at least 100 carries and 4.5+ yards per carry. Return name, team, carries, yards, TDs, and YPC. Sort by YPC descending.
Expected output
| player_display_name | recent_team | carries | yards | tds | ypc |
|---|
Hint
Two HAVING conditions combined with AND. The YPC condition needs to repeat
the aggregate expression (no aliases inside HAVING in standard SQL).
Solution
SELECT player_display_name, recent_team, SUM(carries) AS carries, SUM(rushing_yards) AS yards, SUM(rushing_tds) AS tds, ROUND(SUM(rushing_yards)::numeric / SUM(carries), 2) AS ypcFROM weekly_statsWHERE season = 2024 AND season_type = 'REG' AND position_group = 'RB' AND carries IS NOT NULLGROUP BY player_display_name, recent_teamHAVING SUM(carries) >= 100 AND SUM(rushing_yards)::numeric / NULLIF(SUM(carries), 0) >= 4.5ORDER BY ypc DESC;The expected starter for an All-Pro YPC season is 5.0+. The 100-carry filter keeps QB scramblers out.