Question 1:
You are working with two tables:
1. Game table: This table stores details about football matches, including the id, match
date, (mdate), the teams that played (team1 and team2), and the stadium where the match
was held.
CREATE TABLE Game (
id INT PRIMARY KEY,
mdate DATE,
stadium VARCHAR(255),
team1 CHAR(3),
team2 CHAR(3)
);
INSERT INTO Game (id, mdate, stadium, team1, team2) VALUES
(1001, '2012-06-08', 'National Stadium, Warsaw', 'POL', 'GRE'),
(1002, '2012-06-08', 'Stadion Miejski (Wroclaw)', 'RUS', 'CZE'),
(1003, '2012-06-12', 'Stadion Miejski (Wroclaw)', 'GRE', 'CZE'),
(1004, '2012-06-12', 'National Stadium, Warsaw', 'POL', 'RUS');
2.Goal table: The Goal table specifies the details of goals scored in football matches, including:
● Which match the goal belongs to (matchid).
● Which team scored the goal (teamid).
● The name of the player who scored (player).
● The time during the match when the goal was scored (gtime).
CREATE TABLE Goal (
matchid INT,
teamid CHAR(3),
player VARCHAR(255),
gtime INT,
FOREIGN KEY (matchid) REFERENCES Game(id)
);
INSERT INTO Goal (matchid, teamid, player, gtime) VALUES
(1001, 'POL', 'Robert Lewandowski', 17),
(1001, 'GRE', 'Dimitris Salpingidis', 51),
(1002, 'RUS', 'Alan Dzagoev', 15),
(1002, 'RUS', 'Roman Pavlyuchenko', 82);
Explanation:
Write a query to create a list of every football match along with the number of goals scored by
each team. The output should include the match date, the two teams, and how many goals each
team scored.
Question 2:
You have been given a table named exams that is used to store information about student exam
results.
CREATE TABLE exams (
student_id INT,
subject VARCHAR(20),
marks INT
);
insert into exams values (1,'Chemistry',91),(1,'Physics',91)
,(2,'Chemistry',80),(2,'Physics',90)
,(3,'Chemistry',80)
,(4,'Chemistry',71),(4,'Physics',54);
Task: Write a SQL query to find the IDs of students who have taken both 'Chemistry' and
'Physics' exams. The students must meet these criteria:
● They should have the same score (marks) for both subjects.
● You need to ensure that you only include students who have distinct entries for both
subjects.