-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththe-join-operation.sql
More file actions
71 lines (59 loc) · 1.46 KB
/
Copy paththe-join-operation.sql
File metadata and controls
71 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
60
61
62
63
64
65
66
67
68
69
70
71
--1
SELECT matchid, player
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 JOIN goal ON (id=matchid)
where player like 'Mario%'
--5
SELECT player, teamid, coach, gtime
FROM goal JOIN eteam on teamid=id
WHERE gtime<=10
--6
select mdate, teamname
from game join eteam ON (team1=eteam.id)
where coach='Fernando Santos'
--7
select player
from goal join game on matchid=id
where stadium='National Stadium, Warsaw'
--8
SELECT distinct player
FROM game JOIN goal ON matchid = id
WHERE (team1='GER' and teamid=team2) or (team2='GER' and teamid=team1)
--9
SELECT teamname, count(matchid)
FROM eteam JOIN goal ON id=teamid
group BY teamname
--10
select stadium, count(*)
from game join goal on id=matchid
group by stadium
--11
SELECT matchid,mdate, count(*)
FROM game JOIN goal ON matchid = id
WHERE (team1 = 'POL' OR team2 = 'POL')
group by matchid, mdate
--12
select matchid, mdate, count(*)
from game join goal on matchid=id
where (team1='GER' or team2='GER') and teamid='GER'
group by matchid, mdate
having count(*)>0
--13
SELECT mdate, team1,
sum(case when teamid=team1 then 1 else 0 end) as score1,
team2,
sum(case when teamid=team2 then 1 else 0 end) as score2
from game left join goal ON id = matchid
group by mdate, matchid, team1, team2
order by mdate, matchid, team1, team2;