-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThe-JOIN-Operation.sql
More file actions
59 lines (59 loc) · 1.46 KB
/
The-JOIN-Operation.sql
File metadata and controls
59 lines (59 loc) · 1.46 KB
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
--The JOIN Operation
--1
SELECT matchid, plauyer FROM goal
WHERE teamid = 'GER';
--2
SELECT id, stadium, team1, team2
FROM game
WHERE id = 1012;
--3
SELECT player,teamid, stadium, mdate
FROM game JOIN goal ON id=matchid
WHERE teamid = 'GER';
--4
SELECT team1, team2, player FROM game x
JOIN goal y ON x.id = y.matchid
WHERE player LIKE 'Mario%';
--5
SELECT player, teamid, coach, gtime FROM goal x
JOIN eteam y ON x.teamid = y.id
WHERE gtime <= 10;
--6
SELECT mdate, teamname FROM game x
JOIN eteam y ON team1 = y.id
WHERE coach = 'Fernando Santos';
--7
SELECT player FROM goal x
JOIN game y ON x.id=y.mathcid
WHERE stadium = 'National Stadium, Warsaw';
--8
SELECT DISTINCT x.player FROM goal x
JOIN game y ON (matchid=id)
WHERE teamid != 'GER' AND (team1='GER' OR team2='GER');
--9
SELECT teamname, COUNT(*) goals FROM eteam
JOIN goal ON id=teamid
GROUP BY teamname;
--10
SELECT stadium, COUNT(*) goals FROM game
JOIN goal ON id=matchid
GROUP BY stadium;
--11
SELECT id, mdate, COUNT(*) goals
FROM game JOIN ON matchid=id
WHERE (team1='POL' OR team2 = 'POL')
GROUP BY id, mdate
ORDER BY id;
--12
SELECT id, mdate, COUNT(*) goals FROM game
JOIN goal ON id=matchid
WHERE teamid='Ger'
GROUP BY id, mdate;
--13
SELECT x.mdate, x.team1,
SUM(CASE WHEN y.teamid = x.team1 THEN 1 ELSE 0 END) AS score1,
x.team2,
SUM(CASE WHEN y.teamid = x.team2 THEN 1 ELSE 0 END) AS score2
FROM game x LEFT JOIN goal y ON x.id = y.matchid
GROUP BY x.mdate, x.team1, x.team2
ORDER BY x.mdate, y.matchid, x.team1, x.team2;