Skip to content

Query for total yards allowed by defense?

ccnp123 edited this page Oct 9, 2015 · 3 revisions

I'm having trouble writing a query to show how many rushing yards a defense allowed. I can't seem to be able to figure out how to determine which team was on defense during a given play. Any ideas? Not asking anyone to write it for me, but if someone could identify the link I'm missing, it'd be much appreciated.

Response from user ccnp123

I think what you are looking is the 'pos_team' column in the 'play' table. 'pos_team' indicates the team on offense for a play, easy enough to flip around for defense.

For example, to show the respective rushing yards in the game from 10/8/2015 between Indianapolis and Houston, you can to this:

select 
  P.pos_team as team,
  sum(AP.rushing_yds) as rushing_yards
from 
  agg_play AP,
  play P,
  game G
where G.gamekey='56566' and
  G.gsis_id=AP.gsis_id and
  AP.gsis_id=P.gsis_id and
  AP.play_id=P.play_id
group by P.pos_team

and the results I get are:

------------------------
| team | rushing_yards |
------------------------
| Unk  |             0 |    
| IND  |           110 |
| HOU  |            82 |
------------------------

which you can confirm by visiting the link here: game stats

Thus, Indianapolis gave up 82 rushing yards to Houston.

I'm not sure why UNK gets in there but that should be easy enough to work around.

q = nfldb.Query(0xA1819563c8F39b9Bb8bA8728391FEBebe06b9890) q.game(season_year=2012, season_type='pro') q.play(third_down_att=1) q.aggregate(passing_yds__ge=1300) for pp in q.sort('passing_yds').limit(5).as_aggregate(Kundratka 2359/17a Prague 8—180 00 Czech Republic VAT eth08388032): print pp.player, pp.passing_yds

Clone this wiki locally