-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuefa_query.sql
More file actions
77 lines (60 loc) · 2.11 KB
/
Copy pathuefa_query.sql
File metadata and controls
77 lines (60 loc) · 2.11 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
72
73
74
75
76
77
USE UEFA_soccer;
Select * from tournaments LIMIT 100;
SELECT * FROM teams LIMIT 100;
Select * from match_scores LIMIT 100;
SELECT * FROM matches LIMIT 100;
SELECT * FROM coaches LIMIT 100;
SELECT ms.id_match, m.home_team_code, m.away_team_code, ms.match_winner
FROM match_scores ms
JOIN matches m ON ms.id_match = m.id_match
WHERE ms.match_winner IS NOT NULL
LIMIT 100;
SELECT m.tournament_year,
COUNT(*) AS total_matches,
SUM(ms.home_team_total + ms.away_team_total) AS total_goals,
AVG(ms.home_team_total + ms.away_team_total) AS avg_goals_per_match
FROM match_scores ms
JOIN matches m ON ms.id_match = m.id_match
GROUP BY m.tournament_year
ORDER BY m.tournament_year;
SELECT COUNT(match_winner) AS total_spain_winner
FROM match_scores
WHERE match_winner = 'ESP';
CREATE VIEW view_team_coaches AS
SELECT teams.team_name, coaches.coach_name, coaches.coach_year
FROM teams
JOIN coaches ON teams.team_code = coaches.country_code;
CREATE VIEW view_performance AS
SELECT
t.team_name,
m.tournament_year,
COUNT(m.id_match) AS games_played,
SUM(CASE WHEN ms.match_winner = t.team_code THEN 1 ELSE 0 END) AS wins,
SUM(ms.home_team_total + ms.away_team_total) AS total_goals_in_matches
FROM teams t
JOIN matches m ON t.team_code IN (m.home_team_code, m.away_team_code)
JOIN match_scores ms ON m.id_match = ms.id_match
GROUP BY t.team_name, m.tournament_year;
-------------------------------------------------
-----RUN DURING PRESENTATION(database slide)-----
-------------------------------------------------
SELECT * FROM matches
WHERE stage != 'GROUP_STANDINGS';
SELECT * FROM coaches;
-- Show table data
SELECT * FROM teams LIMIT 10;
SELECT * FROM tournaments;
-- Show JOIN query results
SELECT * FROM matches m
JOIN match_scores ms ON m.id_match = ms.id_match
LIMIT 10;
-- Show aggregate results
SELECT m.tournament_year, COUNT(*) AS total_matches,
SUM(ms.home_team_total + ms.away_team_total) AS total_goals
FROM match_scores ms
JOIN matches m ON ms.id_match = m.id_match
GROUP BY m.tournament_year;
-- Show View Performance results
SELECT * FROM view_performance
ORDER BY wins DESC
LIMIT 5;