-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathqueries.hql
executable file
·729 lines (627 loc) · 42.1 KB
/
queries.hql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
set hive.cli.print.header=true;
! echo "****** Precipitation ******";
! echo "Play break down without precipitation";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where rooftype <> "None" and prcp <= 0 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where rooftype <> "None" and prcp <= 0) totalstable
order by playtype;
! echo "Play break down with precipitation";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where rooftype = "None" and prcp > 0 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where rooftype = "None" and prcp > 0) totalstable
order by playtype;
! echo "****** Wind Speeds ******";
! echo "0-9 Miles per hour";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where rooftype = "None" and awnd < 44 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where rooftype = "None" and awnd < 44) totalstable
order by playtype;
! echo "10-19 Miles per hour";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where rooftype = "None" and awnd >= 44 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where rooftype = "None" and awnd >= 44) totalstable
order by playtype;
! echo "20-29 Miles per hour";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where rooftype = "None" and awnd between 45 and 89 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where rooftype = "None" and awnd between 45 and 89) totalstable
order by playtype;
! echo "30-39 Miles per hour";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where rooftype = "None" and awnd between 90 and 134 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where rooftype = "None" and awnd between 90 and 134) totalstable
order by playtype;
! echo "Above 40 Miles per hour";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where rooftype = "None" and awnd > 135 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where rooftype = "None" and awnd > 135) totalstable
order by playtype;
! echo "With roof";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where rooftype <> "None" group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where rooftype <> "None") totalstable
order by playtype;
! echo "****** WV and WT Play Types ******";
! echo "WV07 Ash, dust, sand, or other blowing obstruction";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where rooftype = "None" and WV07 > 0 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where rooftype = "None" and WV07 > 0) totalstable
order by playtype;
! echo "WV01 Fog, ice fog, or freezing fog";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where rooftype = "None" and WV01 > 0 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where rooftype = "None" and WV01 > 0) totalstable
order by playtype;
! echo "WV20 Rain or snow shower";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where rooftype = "None" and WV20 > 0 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where rooftype = "None" and WV20 > 0) totalstable
order by playtype;
! echo "WV03 Thunder";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where rooftype = "None" and WV03 > 0 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where rooftype = "None" and WV03 > 0) totalstable
order by playtype;
! echo "WT09 Blowing or drifting snow";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where rooftype = "None" and WT09 > 0 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where rooftype = "None" and WT09 > 0) totalstable
order by playtype;
! echo "WT14 Drizzle";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where rooftype = "None" and WT14 > 0 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where rooftype = "None" and WT14 > 0) totalstable
order by playtype;
! echo "WT07 Dust, volcanic ash, blowing dust, blowing sand, or blowing obstruction";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where rooftype = "None" and WT07 > 0 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where rooftype = "None" and WT07 > 0) totalstable
order by playtype;
! echo "WT01 Fog, ice fog, or freezing fog";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where rooftype = "None" and WT01 > 0 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where rooftype = "None" and WT01 > 0) totalstable
order by playtype;
! echo "WT15 Freezing drizzle";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where rooftype = "None" and WT15 > 0 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where rooftype = "None" and WT15 > 0) totalstable
order by playtype;
! echo "WT17 Freezing rain";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where rooftype = "None" and WT17 > 0 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where rooftype = "None" and WT17 > 0) totalstable
order by playtype;
! echo "WT06 Glaze or rime";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where rooftype = "None" and WT06 > 0 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where rooftype = "None" and WT06 > 0) totalstable
order by playtype;
! echo "WT21 Ground fog";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where rooftype = "None" and WT21 > 0 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where rooftype = "None" and WT21 > 0) totalstable
order by playtype;
! echo "WT05 Hail";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where rooftype = "None" and WT05 > 0 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where rooftype = "None" and WT05 > 0) totalstable
order by playtype;
! echo "WT02 Heavy fog or heaving freezing fog";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where rooftype = "None" and WT02 > 0 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where rooftype = "None" and WT02 > 0) totalstable
order by playtype;
! echo "WT11 High or damaging winds";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where rooftype = "None" and WT11 > 0 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where rooftype = "None" and WT11 > 0) totalstable
order by playtype;
! echo "WT22 Ice fog or freezing fog";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where rooftype = "None" and WT22 > 0 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where rooftype = "None" and WT22 > 0) totalstable
order by playtype;
! echo "WT04 Ice pellets, sleet, snow pellets, or small hail";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where rooftype = "None" and WT04 > 0 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where rooftype = "None" and WT04 > 0) totalstable
order by playtype;
! echo "WT13 Mist";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where rooftype = "None" and WT13 > 0 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where rooftype = "None" and WT13 > 0) totalstable
order by playtype;
! echo "WT16 Rain";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where rooftype = "None" and WT16 > 0 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where rooftype = "None" and WT16 > 0) totalstable
order by playtype;
! echo "WT08 Smoke or haze";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where rooftype = "None" and WT08 > 0 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where rooftype = "None" and WT08 > 0) totalstable
order by playtype;
! echo "WT18 Snow, snow pellets, snow grains, or ice crystals";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where rooftype = "None" and WT18 > 0 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where rooftype = "None" and WT18 > 0) totalstable
order by playtype;
! echo "WT03 Thunder";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where rooftype = "None" and WT03 > 0 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where rooftype = "None" and WT03 > 0) totalstable
order by playtype;
! echo "WT10 Tornado, waterspout, or funnel cloud";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where rooftype = "None" and WT10 > 0 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where rooftype = "None" and WT10 > 0) totalstable
order by playtype;
! echo "WT19 Unknown source of precipitation";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where rooftype = "None" and WT19 > 0 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where rooftype = "None" and WT19 > 0) totalstable
order by playtype;
! echo "****** Temperature ******";
! echo "Below 32 F";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where rooftype = "None" and TMAX < 0 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where rooftype = "None" and TMAX < 0) totalstable
order by playtype;
! echo "45 to 33 F";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where rooftype = "None" and TMAX between 1 and 70 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where rooftype = "None" and TMAX between 1 and 70) totalstable
order by playtype;
! echo "46 to 55 F";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where rooftype = "None" and TMAX between 71 and 120 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where rooftype = "None" and TMAX between 71 and 120) totalstable
order by playtype;
! echo "56 to 65 F";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where rooftype = "None" and TMAX between 121 and 180 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where rooftype = "None" and TMAX between 121 and 180) totalstable
order by playtype;
! echo "66 to 75 F";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where rooftype = "None" and TMAX between 181 and 238 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where rooftype = "None" and TMAX between 181 and 238) totalstable
order by playtype;
! echo "76 to 85 F";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where rooftype = "None" and TMAX between 239 and 294 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where rooftype = "None" and TMAX between 239 and 294) totalstable
order by playtype;
! echo "86 to 95 F";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where rooftype = "None" and TMAX between 295 and 350 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where rooftype = "None" and TMAX between 295 and 350) totalstable
order by playtype;
! echo "Above 96 F";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where rooftype = "None" and TMAX > 351 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where rooftype = "None" and TMAX > 351) totalstable
order by playtype;
! echo "****** Play Type by Down ******";
! echo "First";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where down = 1 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where down = 1) totalstable
order by playtype;
! echo "Second";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where down = 2 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where down = 2) totalstable
order by playtype;
! echo "Third";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where down = 3 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where down = 3) totalstable
order by playtype;
! echo "Fourth";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where down = 4 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where down = 4) totalstable
order by playtype;
! echo "****** Play Type by Yards to Go ******";
! echo "All";
select pertotalstable.playtype, pertotalstable.yardstogo, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, yardstogo, count(*) as totalperplay from playbyplay group by yardstogo, playtype) pertotalstable
join
(select yardstogo, count(*) as total from playbyplay group by yardstogo) totalstable
on totalstable.yardstogo = pertotalstable.yardstogo
order by yardstogo, playtype;
! echo "Sack and Scrambles";
select pertotalstable.playtype, pertotalstable.yardstogo, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, yardstogo, count(*) as totalperplay from playbyplay where (playtype = "SACK" OR playtype = "SCRAMBLE") group by yardstogo, playtype) pertotalstable
join
(select yardstogo, count(*) as total from playbyplay group by yardstogo) totalstable
on totalstable.yardstogo = pertotalstable.yardstogo
order by percentage;
! echo "****** Wins by Arrests ******";
! echo "All";
select hometeamwon, awayteamwon, HomeTeamPlayerArrested, AwayTeamPlayerArrested, pertotalstable.totalperarrest, totalstable.total, ((pertotalstable.totalperarrest / totalstable.total) * 100) as percentage from
(select hometeamwon, awayteamwon, HomeTeamPlayerArrested, AwayTeamPlayerArrested, count(*) as totalperarrest from
(select distinct game, (winner = hometeam) as hometeamwon, (winner = awayteam) as awayteamwon, HomeTeamPlayerArrested, AwayTeamPlayerArrested from playbyplay) pertotalstable
group by hometeamwon, awayteamwon, HomeTeamPlayerArrested, AwayTeamPlayerArrested) pertotalstable
full outer join
(select count(*) as total from
(select game from playbyplay group by game) pertotalstable) totalstable;
! echo "****** Arrests by Season ******";
! echo "All";
select year, count(*) as totalperarrest from
(select hometeam, year from playbyplay where HomeTeamPlayerArrested = true group by year, hometeam) pertotalstable
group by year;
! echo "By team per season";
select hometeam, count(*) as totalperarrest from
(select hometeam, year from playbyplay where HomeTeamPlayerArrested = true group by year, hometeam) pertotalstable
group by hometeam
order by totalperarrest;
! echo "****** Wins by home team ******";
! echo "All";
select pertotalstable.totalhometeamwins, totalstable.total, ((pertotalstable.totalhometeamwins / totalstable.total) * 100) as percentage from
(select count(*) as totalhometeamwins from
(select distinct game, (winner = hometeam) as hometeamwon from playbyplay) pertotalstable
where hometeamwon = true) pertotalstable
full outer join
(select count(*) as total from
(select distinct game from playbyplay) pertotalstable
) totalstable;
! echo "****** Wins by home team when there is bad weather ******";
! echo "hasWeatherInVicinity";
select pertotalstable.totalhometeamwins, totalstable.total, ((pertotalstable.totalhometeamwins / totalstable.total) * 100) as percentage from
(select count(*) as totalhometeamwins from
(select distinct game, (winner = hometeam) as hometeamwon from playbyplay where hasWeatherInVicinity = true) pertotalstable
where hometeamwon = true) pertotalstable
full outer join
(select count(*) as total from
(select distinct game from playbyplay where hasWeatherInVicinity = true) pertotalstable
) totalstable;
! echo "hasWeatherType";
select pertotalstable.totalhometeamwins, totalstable.total, ((pertotalstable.totalhometeamwins / totalstable.total) * 100) as percentage from
(select count(*) as totalhometeamwins from
(select distinct game, (winner = hometeam) as hometeamwon from playbyplay where hasWeatherType = true) pertotalstable
where hometeamwon = true) pertotalstable
full outer join
(select count(*) as total from
(select distinct game from playbyplay where hasWeatherType = true) pertotalstable
) totalstable;
! echo "hasWeather";
select pertotalstable.totalhometeamwins, totalstable.total, ((pertotalstable.totalhometeamwins / totalstable.total) * 100) as percentage from
(select count(*) as totalhometeamwins from
(select distinct game, (winner = hometeam) as hometeamwon from playbyplay where hasWeather = true) pertotalstable
where hometeamwon = true) pertotalstable
full outer join
(select count(*) as total from
(select distinct game from playbyplay where hasWeather = true) pertotalstable
) totalstable;
! echo "****** Fumbles, penalty and incompletes by weather ******";
! echo "Plays with Weather";
select totalweatherfumbles, total, ((pertotalstable.totalweatherfumbles / totalstable.total) * 100) as percentage from
(select count(*) as totalweatherfumbles from
(select game from playbyplay where hasWeather = true) pertotalstable)
playbyplay
full outer join
(select count(*) as total from playbyplay) totalstable;
! echo "Fumbles by game";
select hasWeather, totalweatherfumbles, total, ((pertotalstable.totalweatherfumbles / totalstable.total) * 100) as percentage from
(select hasWeather, count(*) as totalweatherfumbles from
(select game, hasWeather from playbyplay where fumble = true group by game, hasWeather) pertotalstable
group by hasWeather) pertotalstable
full outer join
(select count(*) as total from
(select game from playbyplay where fumble = true group by game) pertotalstable
) totalstable;
! echo "Penalty by plays";
select pertotalstable.hasWeather, totalweatherpenalty, total, ((pertotalstable.totalweatherpenalty / totalstable.total) * 100) as percentage from
(select hasWeather, count(*) as totalweatherpenalty from
(select hasWeather from playbyplay where penalty = true) pertotalstable
group by hasWeather)
playbyplay
join
(select hasWeather, count(*) as total from playbyplay group by hasWeather) totalstable
on pertotalstable.hasWeather = totalstable.hasWeather;
! echo "Incomplete by plays";
select pertotalstable.hasWeather, totalweatherpenalty, total, ((pertotalstable.totalweatherpenalty / totalstable.total) * 100) as percentage from
(select hasWeather, count(*) as totalweatherpenalty from
(select hasWeather from playbyplay where incomplete = true) pertotalstable
group by hasWeather)
playbyplay
join
(select hasWeather, count(*) as total from playbyplay group by hasWeather) totalstable
on pertotalstable.hasWeather = totalstable.hasWeather;
! echo "****** TODO: Nemesis - Offense and Defense co-occurrence ******";
! echo "QB";
--select OffensivePlayer, DefensivePlayer, total from
--(
-- select OffensivePlayer, DefensivePlayer, count(*) as total from
-- (
-- (select OffensivePlayer, DefensivePlayer1 as DefensivePlayer from playbyplay where OffensivePlayer <> "" and DefensivePlayer1 <> "")
-- union all
-- (select OffensivePlayer, DefensivePlayer2 as DefensivePlayer from playbyplay where OffensivePlayer <> "" and DefensivePlayer2 <> "")
-- ) pertotalstable
-- group by OffensivePlayer, DefensivePlayer
--) pertotalstable
--order by total DESC limit 100;
! echo "OffensivePlayer";
! echo "****** Crowd capacity and scoring ******";
! echo "All";
select capacity, avg(HomeTeamScore) as homeTeamAverage, avg(AwayTeamScore) as awayTeamAverage from
(select game, capacity, homeTeamScore, AwayTeamScore from playbyplay group by game, capacity, homeTeamScore, AwayTeamScore) pertotalstable
group by capacity
order by capacity desc;
! echo "****** Scoring by weather type ******";
! echo "hasWeatherInVicinity true";
select * from
(select hometeam, hasWeatherInVicinity, avg(HomeTeamScore) as homeTeamAverage, avg(AwayTeamScore) as awayTeamAverage from
(select hometeam, homeTeamScore, AwayTeamScore, hasWeatherInVicinity from playbyplay
where hasWeatherInVicinity = true and rooftype = "None"
group by game, hometeam, homeTeamScore, AwayTeamScore, hasWeatherInVicinity) pertotalstable
group by hometeam, hasWeatherInVicinity) pertotalstable
order by hometeam, hasWeatherInVicinity;
! echo "hasWeatherInVicinity false";
select * from
(select hometeam, hasWeatherInVicinity, avg(HomeTeamScore) as homeTeamAverage, avg(AwayTeamScore) as awayTeamAverage from
(select hometeam, homeTeamScore, AwayTeamScore, hasWeatherInVicinity from playbyplay
where hasWeatherInVicinity = false OR rooftype <> "None"
group by game, hometeam, homeTeamScore, AwayTeamScore, hasWeatherInVicinity) pertotalstable
group by hometeam, hasWeatherInVicinity) pertotalstable
order by hometeam, hasWeatherInVicinity;
! echo "hasWeatherType true";
select * from
(select hometeam, hasWeatherType, avg(HomeTeamScore) as homeTeamAverage, avg(AwayTeamScore) as awayTeamAverage from
(select hometeam, homeTeamScore, AwayTeamScore, hasWeatherType from playbyplay
where hasWeatherType = true and rooftype = "None"
group by game, hometeam, homeTeamScore, AwayTeamScore, hasWeatherType) pertotalstable
group by hometeam, hasWeatherType) pertotalstable
order by hometeam, hasWeatherType;
! echo "hasWeatherType false";
select * from
(select hometeam, hasWeatherType, avg(HomeTeamScore) as homeTeamAverage, avg(AwayTeamScore) as awayTeamAverage from
(select hometeam, homeTeamScore, AwayTeamScore, hasWeatherType from playbyplay
where hasWeatherType = false OR rooftype <> "None"
group by game, hometeam, homeTeamScore, AwayTeamScore, hasWeatherType) pertotalstable
group by hometeam, hasWeatherType) pertotalstable
order by hometeam, hasWeatherType;
! echo "hasWeather true";
select * from
(select hometeam, hasWeather, avg(HomeTeamScore) as homeTeamAverage, avg(AwayTeamScore) as awayTeamAverage from
(select hometeam, homeTeamScore, AwayTeamScore, hasWeather from playbyplay
where hasWeather = true and rooftype = "None"
group by game, hometeam, homeTeamScore, AwayTeamScore, hasWeather) pertotalstable
group by hometeam, hasWeather) pertotalstable
order by hometeam, hasWeather;
! echo "hasWeather false";
select * from
(select hometeam, avg(HomeTeamScore) as homeTeamAverage, avg(AwayTeamScore) as awayTeamAverage from
(select hometeam, homeTeamScore, AwayTeamScore from playbyplay
where hasWeather = false OR rooftype <> "None"
group by game, hometeam, homeTeamScore, AwayTeamScore) pertotalstable
group by hometeam) pertotalstable
order by hometeam;
! echo "****** Field goals makes by weather type ******";
! echo "hasWeatherInVicinity true";
select * from
(select IsGoalGood, hasWeatherInVicinity, count(*) from playbyplay
where hasWeatherInVicinity = true AND rooftype = "None" AND (playtype = "FIELDGOAL")
group by IsGoalGood, hasWeatherInVicinity) pertotalstable
order by IsGoalGood, hasWeatherInVicinity;
! echo "hasWeatherInVicinity false";
select * from
(select IsGoalGood, hasWeatherInVicinity, count(*) from playbyplay
where (hasWeatherInVicinity = false OR rooftype <> "None") AND (playtype = "FIELDGOAL")
group by IsGoalGood, hasWeatherInVicinity) pertotalstable
order by IsGoalGood, hasWeatherInVicinity;
! echo "hasWeatherType true";
select * from
(select IsGoalGood, hasWeatherType, count(*) from playbyplay
where hasWeatherType = true AND rooftype = "None" AND (playtype = "FIELDGOAL")
group by IsGoalGood, hasWeatherType) pertotalstable
order by IsGoalGood, hasWeatherType;
! echo "hasWeatherType false";
select * from
(select IsGoalGood, hasWeatherType, count(*) from playbyplay
where (hasWeatherType = false OR rooftype <> "None") AND (playtype = "FIELDGOAL")
group by IsGoalGood, hasWeatherType) pertotalstable
order by IsGoalGood, hasWeatherType;
! echo "hasWeather true";
select * from
(select IsGoalGood, hasWeather, count(*) from playbyplay
where hasWeather = true AND rooftype = "None" AND (playtype = "FIELDGOAL")
group by IsGoalGood, hasWeather) pertotalstable
order by IsGoalGood, hasWeather;
! echo "hasWeather false";
select * from
(select IsGoalGood, hasWeather, count(*) from playbyplay
where (hasWeather = false OR rooftype <> "None") AND (playtype = "FIELDGOAL")
group by IsGoalGood, hasWeather) pertotalstable
order by IsGoalGood, hasWeather;
! echo "****** The break down of how many plays occur on which yard line ******";
! echo "All";
select yardline, count(*) from playbyplay
group by yardline
order by yardline;
-- Scores by artificial turf and grass
-- Play types broken down by team
-- Stadium capacity and wins
-- Fumbles by down
! echo "****** Missed field goals by wind ******";
! echo "0-9 Miles per hour";
select IsGoalGood, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select IsGoalGood, count(*) as totalperplay from playbyplay where playtype = "FIELDGOAL" AND rooftype = "None" and awnd < 44 group by IsGoalGood) pertotalstable
full outer join
(select count(*) as total from playbyplay where playtype = "FIELDGOAL" AND rooftype = "None" and awnd < 44) totalstable
order by IsGoalGood;
! echo "10-19 Miles per hour";
select IsGoalGood, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select IsGoalGood, count(*) as totalperplay from playbyplay where playtype = "FIELDGOAL" AND rooftype = "None" and awnd >= 44 group by IsGoalGood) pertotalstable
full outer join
(select count(*) as total from playbyplay where playtype = "FIELDGOAL" AND rooftype = "None" and awnd >= 44) totalstable
order by IsGoalGood;
! echo "20-29 Miles per hour";
select IsGoalGood, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select IsGoalGood, count(*) as totalperplay from playbyplay where playtype = "FIELDGOAL" AND rooftype = "None" and awnd between 45 and 89 group by IsGoalGood) pertotalstable
full outer join
(select count(*) as total from playbyplay where playtype = "FIELDGOAL" AND rooftype = "None" and awnd between 45 and 89) totalstable
order by IsGoalGood;
! echo "30-39 Miles per hour";
select IsGoalGood, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select IsGoalGood, count(*) as totalperplay from playbyplay where playtype = "FIELDGOAL" AND rooftype = "None" and awnd between 90 and 134 group by IsGoalGood) pertotalstable
full outer join
(select count(*) as total from playbyplay where playtype = "FIELDGOAL" AND rooftype = "None" and awnd between 90 and 134) totalstable
order by IsGoalGood;
! echo "Above 40 Miles per hour";
select IsGoalGood, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select IsGoalGood, count(*) as totalperplay from playbyplay where playtype = "FIELDGOAL" AND rooftype = "None" and awnd > 135 group by IsGoalGood) pertotalstable
full outer join
(select count(*) as total from playbyplay where playtype = "FIELDGOAL" AND rooftype = "None" and awnd > 135) totalstable
order by IsGoalGood;
! echo "With roof";
select IsGoalGood, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select IsGoalGood, count(*) as totalperplay from playbyplay where playtype = "FIELDGOAL" AND rooftype <> "None" group by IsGoalGood) pertotalstable
full outer join
(select count(*) as total from playbyplay where playtype = "FIELDGOAL" AND rooftype <> "None") totalstable
order by IsGoalGood;
! echo "Play types by elevation";
! echo "Sea Level";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where elevation < 100 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where elevation < 100) totalstable
order by playtype;
! echo "Mid Range";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where elevation between 100 and 5000 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where elevation between 100 and 5000) totalstable
order by playtype;
! echo "Mountain";
select playtype, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select playtype, count(*) as totalperplay from playbyplay where elevation > 5000 group by playtype) pertotalstable
full outer join
(select count(*) as total from playbyplay where elevation > 5000) totalstable
order by playtype;
! echo "Play results by yard started on";
! echo "By Play";
select pertotalstable.yardline, pertotalstable.driveresult, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select driveresult, yardline, count(*) as totalperplay from playbyplay where play = 1 and driveresult <> "KICKOFF" GROUP BY driveresult, yardline) pertotalstable
join
(select count(*) as total, yardline from playbyplay where play = 1 and driveresult <> "KICKOFF" GROUP BY yardline) totalstable
ON (totalstable.yardline = pertotalstable.yardline)
order by yardline, driveresult;
! echo "By Scoring";
select pertotalstable.yardline, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select yardline, count(*) as totalperplay
from playbyplay where play = 1 and (driveresult = "EXTRAPOINT" OR driveresult = "FIELDGOAL") AND driveresult <> "KICKOFF"
GROUP BY yardline) pertotalstable
join
(select count(*) as total, yardline from playbyplay where play = 1 AND driveresult <> "KICKOFF" GROUP BY yardline) totalstable
ON (totalstable.yardline = pertotalstable.yardline)
order by yardline;
! echo "Starting at 80 yardline and up";
select pertotalstable.driveresult, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select driveresult, count(*) as totalperplay from playbyplay where play = 1 and driveresult <> "KICKOFF" and yardline >= 80 GROUP BY driveresult) pertotalstable
full outer join
(select count(*) as total from playbyplay where play = 1 and yardline >= 80 and driveresult <> "KICKOFF") totalstable
order by driveresult;
! echo "Starting at 20 to 80 yardline";
select pertotalstable.driveresult, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select driveresult, count(*) as totalperplay from playbyplay where play = 1 and driveresult <> "KICKOFF" and yardline < 80 and yardline > 20 GROUP BY driveresult) pertotalstable
full outer join
(select count(*) as total from playbyplay where play = 1 and yardline < 80 and yardline > 20 and driveresult <> "KICKOFF") totalstable
order by driveresult;
! echo "Red Zone starting at 0 to 20 yardline";
select pertotalstable.driveresult, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select driveresult, count(*) as totalperplay from playbyplay where play = 1 and driveresult <> "KICKOFF" and yardline <= 20 GROUP BY driveresult) pertotalstable
full outer join
(select count(*) as total from playbyplay where play = 1 and yardline <= 20 and driveresult <> "KICKOFF") totalstable
order by driveresult;
! echo "All Yardlines";
select pertotalstable.driveresult, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select driveresult, count(*) as totalperplay from playbyplay where play = 1 and driveresult <> "KICKOFF" GROUP BY driveresult) pertotalstable
full outer join
(select count(*) as total from playbyplay where play = 1 and driveresult <> "KICKOFF") totalstable
order by driveresult;
! echo "Drives";
! echo "Number of drives";
select count(*) from playbyplay where play = 1 and driveresult <> "KICKOFF";
! echo "Breakdown of results for all drives";
select pertotalstable.driveresult, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select driveresult, count(*) as totalperplay from playbyplay where play = 1 and driveresult <> "KICKOFF" GROUP BY driveresult) pertotalstable
full outer join
(select count(*) as total from playbyplay where play = 1 and driveresult <> "KICKOFF") totalstable
order by driveresult;
! echo "Yardline where drives start";
select pertotalstable.yardline, pertotalstable.totalperplay, totalstable.total, ((pertotalstable.totalperplay / totalstable.total) * 100) as percentage from
(select yardline, count(*) as totalperplay from playbyplay where play = 1 and driveresult <> "KICKOFF" GROUP BY yardline) pertotalstable
full outer join
(select count(*) as total from playbyplay where play = 1 and driveresult <> "KICKOFF") totalstable
order by yardline;
! echo "Drives and Plays";
! echo "Average number of plays in a drive and the maximum number of plays in a drive";
select avg(maxplays), max(maxplays) from playbyplay where play = 1 and driveresult <> "KICKOFF";
! echo "Average number of plays in a drive and the maximum number of plays in a drive broken down by stadium";
select stadium, avg(maxplays), max(maxplays) from playbyplay where play = 1 and driveresult <> "KICKOFF" GROUP BY stadium order by stadium;
! echo "Average number of plays in a drive and the maximum number of plays in a drive broken down by team";
select offense, avg(maxplays), max(maxplays) from playbyplay where play = 1 and driveresult <> "KICKOFF" GROUP BY offense order by offense;
! echo "Average number of plays in a drive and the maximum number of plays in a drive with weather";
select avg(maxplays), max(maxplays) from playbyplay where play = 1 and driveresult <> "KICKOFF" GROUP BY hasweather;
! echo "Average number of plays in a drive and the maximum number of plays in a drive broken down by stadium with weather";
select stadium, hasweather, avg(maxplays), max(maxplays) from playbyplay where play = 1 and driveresult <> "KICKOFF" GROUP BY hasweather, stadium order by stadium, hasweather;
! echo "Average number of plays in a drive and the maximum number of plays in a drive broken down by team with weather";
select offense, hasweather, avg(maxplays), max(maxplays) from playbyplay where play = 1 and driveresult <> "KICKOFF" GROUP BY hasweather, offense order by offense, hasweather;
! echo "Average number of plays in a drive and the maximum number of plays in a drive with precipitation";
select avg(maxplays), max(maxplays) from playbyplay where play = 1 and driveresult <> "KICKOFF" and prcp > 0;
! echo "Touchbacks";
! echo "Touchbacks by year";
select pertotalstable.year, pertotalstable.totaltouchbackperyear, totalstable.totalperyear, ((pertotalstable.totaltouchbackperyear / totalstable.totalperyear) * 100) as percentage from
(select count(*) as totaltouchbackperyear, year from playbyplay where playtype = "KICKOFF" and LOWER(playdesc) LIKE "%touchback%" GROUP BY year) pertotalstable
join
(select count(*) as totalperyear, year from playbyplay where playtype = "KICKOFF" GROUP BY year) totalstable
on (totalstable.year = pertotalstable.year)
order by year;