Skip to content

Commit 59516e4

Browse files
committed
adding joins exercises
1 parent 6620146 commit 59516e4

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

join.sql

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
SELECT matchid, player FROM goal
2+
WHERE teamid = 'GER'
3+
4+
5+
SELECT id,stadium,team1,team2
6+
FROM game
7+
where id = 1012
8+
9+
10+
11+
SELECT player, teamid, stadium, mdate
12+
FROM game JOIN goal ON (id=matchid)
13+
where teamid = 'GER'
14+
15+
16+
SELECT team1, team2, player
17+
FROM game JOIN goal ON (id=matchid)
18+
where player like 'Mario%'
19+
20+
21+
22+
SELECT player, teamid, coach, gtime
23+
FROM goal JOIN eteam ON (teamid=id)
24+
WHERE gtime<=10
25+
26+
27+
select mdate, teamname
28+
from game JOIN eteam ON (team1=eteam.id)
29+
where coach = 'Fernando Santos'
30+
31+
32+
select player
33+
from goal JOIN game on (matchid = id)
34+
where stadium = 'National Stadium, Warsaw'
35+
36+
37+
38+
SELECT DISTINCT player
39+
FROM game JOIN goal ON matchid = id
40+
WHERE (team1 = 'GER' or team2 = 'GER')
41+
AND teamid != 'GER'
42+
43+
44+
SELECT teamname, COUNT(*) as goals_scored
45+
FROM eteam JOIN goal ON id=teamid
46+
GROUP BY teamname
47+
48+
49+
50+
SELECT stadium, COUNT(*)as goals FROM goal
51+
JOIN game ON (matchid = id)
52+
GROUP BY stadium
53+
54+
55+
SELECT matchid, mdate, COUNT(*)
56+
FROM game JOIN goal ON matchid = id
57+
WHERE (team1 = 'POL' OR team2 = 'POL')
58+
GROUP BY mdate,matchid
59+
order by matchid asc -- PR
60+
61+
62+
63+
SELECT matchid, mdate, COUNT(*) FROM goal
64+
JOIN game ON (matchid=id)
65+
WHERE teamid = 'GER'
66+
GROUP BY matchid, mdate
67+
68+
69+
70+
SELECT DISTINCT mdate, team1,
71+
SUM(CASE WHEN teamid=team1 THEN 1 ELSE 0 END) score1,
72+
team2,
73+
SUM(CASE WHEN teamid=team2 THEN 1 ELSE 0 END) score2
74+
FROM game
75+
LEFT JOIN goal ON game.id = goal.matchid
76+
GROUP BY id, mdate, team1, team2
77+
ORDER BY mdate, matchid, team1, team2

0 commit comments

Comments
 (0)