-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQ11.sql
48 lines (21 loc) · 1.02 KB
/
Q11.sql
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
--Q11.Is there any correlation between number of wins and team salary?
--Use data from 2000 and later to answer this question. As you do this analysis,
--keep in mind that salaries across the whole league tend to increase together,
--so you may want to look on a year-by-year basis.
SELECT * FROM teams
SELECT * FROM salaries
--team/number of win each year >=2000
WITH number_of_win AS (SELECT yearid,teamid,name,w
FROM teams
WHERE yearid >=2000),
-- WITH sum_salary AS (SELECT yearid,teamid,SUM(salary) as total_salary
-- FROM salaries
-- WHERE yearid >=2000
-- GROUP BY yearid,teamid
-- ORDER BY yearid,teamid)
SELECT DISTINCT s.yearid,s.teamid,nw.w,SUM(salary)OVER(PARTITION BY s.yearid,s.teamid) as total_salary
FROM salaries as s
FULL JOIN number_of_win as nw USING(teamid)
WHERE s.yearid = nw.yearid
--GROUP BY s.yearid,s.teamid
ORDER BY s.teamid,s.yearid