0% found this document useful (0 votes)
39 views

CMPE232 SQL Activity

The document describes an SQL activity involving teams, matches, and goals. It includes tables for teams and matches, and poses eight questions to be answered with SQL statements. The answers provided write the necessary SQL code to return the requested data, such as listing all teams, finding a specific match score, calculating totals by team and location, and averaging home team goals.

Uploaded by

obmsecret
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

CMPE232 SQL Activity

The document describes an SQL activity involving teams, matches, and goals. It includes tables for teams and matches, and poses eight questions to be answered with SQL statements. The answers provided write the necessary SQL code to return the requested data, such as listing all teams, finding a specific match score, calculating totals by team and location, and averaging home team goals.

Uploaded by

obmsecret
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

CMPE 232 SQL Activity

Team
Team_Name, City

Match
Host_Team, Guest_Team, Match_Date, Host_Goal, Guest_Goal

 Write the SQL statements for the following questions:


- List all teams with their names.
- List the teams which have matches as a host team.
- How many teams exist?
- What is the score of the match between Beşiktaş and Liverpool played on ‘20/03/2019’?
- Calculate the total number of matches played at İstanbul.
- Calculate the total goals of one of the teams.
- Calculate the total goals of the teams from İstanbul.
- Calculate the average goals of the teams that they play in their home.

ANSWERS:

- List all teams with their names.

SELECT team_name FROM team

- List the teams which have matches as a host team.

SELECT DISTINCT team_name


FROM team t, match m
WHERE t.team_name = m.host_team

- How many teams exist?

SELECT count(*)
FROM team t

- What is the score of the match between Beşiktaş and Liverpool played on ‘20/03/2019’?

SELECT host_goal, guest_goal


FROM match m
WHERE m.host_team = 'Beşiktaş'
AND m.guest_team = 'Liverpool'
AND TO_CHAR (m.match_date, 'DD/MM/YYYY') = '20/03/2019'
- Calculate the total number of matches played at İstanbul.

SELECT count(*)
FROM match m, team t
WHERE m.host_team = t.team_name
AND t.city = 'İstanbul'

- Calculate the total goals of one of the teams.

SELECT SUM (goal)


FROM (SELECT host_goal goal
FROM match m
WHERE m.host_team = 'Beşiktaş'
UNION
SELECT guest_goal goal
FROM match m
WHERE m.guest_team = 'Beşiktaş')

- Calculate the total goals of the teams from İstanbul.

SELECT SUM (goal)


FROM (SELECT host_goal goal
FROM match m, team t
WHERE m.host_team = t.team_name
AND t.city = 'İstanbul'
UNION
SELECT guest_goal goal
FROM match m, team t
WHERE m.host_team = t.team_name
AND t.city = 'İstanbul')

- Calculate the average goals of the teams that they play in their home.

SELECT host_team, avg(host_goal)


FROM match m
GROUP BY host_team

You might also like