-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwide_receiver_code
191 lines (176 loc) · 4.23 KB
/
wide_receiver_code
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
-- inserting data into wide_receiver from csv
COPY wide_receiver
FROM
'C:\Users\bhamm\OneDrive\Documents\FFdb_raw\mySQL\WR.csv'
DELIMITER ','
CSV HEADER;
-- counting week, player (should have 596), games, and season rows
SELECT
COUNT(DISTINCT week),
COUNT(DISTINCT player),
COUNT(DISTINCT games),
COUNT(DISTINCT season)
FROM
wide_receiver;
-- filtering out and deleting wide receivers with no targets or carries in 2023
-- players without 2023 stats add no value to the database
-- first I first count the number of players being dropped before dropping them
SELECT
player
FROM
wide_receiver
WHERE
season = 2023
GROUP BY
player
HAVING
SUM(targets) = 0
AND SUM(carries) = 0;
-- the results of the above query shows 128 players that needed dropped
-- dropping players
DELETE FROM wide_receiver
WHERE player IN (
SELECT
player
FROM
wide_receiver
WHERE
season = 2023
GROUP BY
player
HAVING
SUM(targets) = 0
AND SUM(carries) = 0);
-- running the query below returns 468 players which is 128 less than the we started with
SELECT
COUNT(DISTINCT player)
FROM
wide_receiver;
-- inserting a new field called position
-- this field will help filter data once we model the database
ALTER TABLE wide_receiver
ADD COLUMN position varchar(3);
-- Assigning the position abbreviation to the new field
UPDATE running_back
SET position = 'WR';
-- trimming all whitespaces from text fields
SELECT
trim(player),
trim(team_code),
trim(position)
FROM
wide_receiver;
-- checking for duplicates by cross referencing games played per season
-- creating a pivot table using the FILTER clause to display games played per season
-- max games played per season from 2023-2021 = 17 and from 2020-2018 = 16
-- players with more games played than that suggest errors in the data
SELECT
DISTINCT player,
COALESCE(SUM(games) FILTER(WHERE season = 2023),0) AS "2023",
COALESCE(SUM(games) FILTER(WHERE season = 2022),0) AS "2022",
COALESCE(SUM(games) FILTER(WHERE season = 2021),0) AS "2021",
COALESCE(SUM(games) FILTER(WHERE season = 2020),0) AS "2020",
COALESCE(SUM(games) FILTER(WHERE season = 2019),0) AS "2019",
COALESCE(SUM(games) FILTER(WHERE season = 2018),0) AS "2018"
FROM
wide_receiver
GROUP BY
player
ORDER BY
"2021" DESC,
player;
-- checking DeVonta Smith who had over 18 games in 2021
SELECT *
FROM
wide_receiver
WHERE
player = 'DeVonta Smith'
AND season = 2021
ORDER BY
week;
-- this shows dupicate values for week 13 & 14
-- fantasydata.com shows he had a bye in week 14
-- I will delete the week 14 record
DELETE FROM
wide_receiver
WHERE
player = 'DeVonta Smith'
AND season = 2021
AND week = 14;
-- checking Jalen Reagor who had over 18 games in 2021
SELECT *
FROM
wide_receiver
WHERE
player = 'Jalen Reagor'
AND season = 2021
ORDER BY
week;
-- this shows dupicate values for week 13 & 14
-- fantasydata.com shows he had a bye in week 14
-- I will delete the week 14 record
DELETE FROM
wide_receiver
WHERE
player = 'Jalen Reagor'
AND season = 2021
AND week = 14;
-- checking Kendrick Bourne who had over 18 games in 2021
SELECT *
FROM
wide_receiver
WHERE
player = 'Kendrick Bourne'
AND season = 2021
ORDER BY
week;
-- this shows dupicate values for week 13 & 14
-- fantasydata.com shows he had a bye in week 14
-- I will delete the week 14 record
DELETE FROM
wide_receiver
WHERE
player = 'Kendrick Bourne'
AND season = 2021
AND week = 14;
-- checking Michael Pittman Jr who had over 18 games in 2021
SELECT *
FROM
wide_receiver
WHERE
player = 'Michael Pittman Jr.'
AND season = 2021
ORDER BY
week;
-- this shows dupicate values for week 13 & 14
-- fantasydata.com shows he had a bye in week 14
-- I will delete the week 14 record
DELETE FROM
wide_receiver
WHERE
player = 'Michael Pittman Jr.'
AND season = 2021
AND week = 14;
-- checking Quez Watkins who had over 18 games in 2021
SELECT *
FROM
wide_receiver
WHERE
player = 'Quez Watkins'
AND season = 2021
ORDER BY
week;
-- this shows dupicate values for week 13 & 14
-- fantasydata.com shows he had a bye in week 14
-- I will delete the week 14 record
DELETE FROM
wide_receiver
WHERE
player = 'Quez Watkins'
AND season = 2021
AND week = 14;
trim(player),
trim(team_code),
trim(position)
FROM
wide_receiver;