0% found this document useful (0 votes)
82 views4 pages

Col362 HW1

This document provides instructions for homework 1 on databases. Students are asked to: 1) Install and run PostgreSQL 8.3.23 on their machine. 2) Describe a dataset on FIFA World Cups containing 7 tables. 3) Load the dataset CSV files into the tables in the correct order. 4) Run 5 SQL queries on the dataset and describe what each query is doing. 5) Write 7 SQL queries to analyze the FIFA World Cup dataset.

Uploaded by

Nick Pace
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)
82 views4 pages

Col362 HW1

This document provides instructions for homework 1 on databases. Students are asked to: 1) Install and run PostgreSQL 8.3.23 on their machine. 2) Describe a dataset on FIFA World Cups containing 7 tables. 3) Load the dataset CSV files into the tables in the correct order. 4) Run 5 SQL queries on the dataset and describe what each query is doing. 5) Write 7 SQL queries to analyze the FIFA World Cup dataset.

Uploaded by

Nick Pace
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/ 4

Homework - 1

COL362 - Introduction to DBMS


Due Date: 11:59 PM January 23, 2023

Instructions
Instructions

1. This homework is not graded. But it is mandatory to submit the homework.


2. All work has to be done individually – this is not group activity.
3. Command to run .sql files: psql \i path/to/file.sql.

4. Submit Entry-Number.txt and Entry-Number.sql files. For ’Installation and Compi-


lation’ part and Exercise - 1, submit your output in Entry-Number.txt (a single PDF
file). For Exercise - 2, submit Entry-Number.sql file. Follow the given format for .sql
file. Leave an empty line after each query
-1-
SQL Query-1
-2-
SQL Query-2
-3-
SQL Query-3
5. Use only piazza for your queries. Don’t contact TAs through any other platform.
Tag posts related to the homework with “homework1” tag.

1 Installation and Compilation


In this part of the homework, you will be required to download, compile and install the Post-
greSQL 8.3.23 database management system on your machine. Please make sure you do not have
any previous installation of PostgreSQL in your machine before you start this – if you have, you
must uninstall.

1. Download the source files of PostgreSQL 8.3.23 from https://www.postgresql.org/


ftp/source/v8.3.23/.
2. Make sure you have the clang 14 compiler on your system. You can install it easily on Linux-
like systems (it is default in Mac). For Windows 10 users, we have tested using Windows
Subsystem for Linux (WSL). If you have a different set up, your mileage may vary.
3. Compile/build from sources PostreSQL 8.3.23 using the instructions provided in the doc-
umentation here. You also have installation instructions in the INSTALL document in the
sources you have downloaded. Follow the instructions carefully.

• You can install PostgreSQL in the default directory. But if you would like, you can also
install it in as separate directory (for ease of removal later), by passing appropriate
arguments to the configure script. Please read the configure help for more details.

1
• On some machines – namely, the Mac machines with M1/M2 chip – you may get an
error saying the platform does not support spinlocks. You can turn it off by passing
the appropriate argument to the configure script. On all other machines you will
not have this issue.
4. After successful installation, run psql in the terminal and in the prompt run query: SELECT
version(); and submit the output in the report. Subsequently, all the SQL queries should
be run in psql prompt.

2 Dataset Description
We all still fondly remember the exciting finals game of FIFA WC’22 between Argentina and
France which is considered one of the greatest football matches ever. In this homework, we take
a little bit of history tour and go back in time to look at the past FIFA WCs.
This is a comprehensive database about the FIFA World Cups, that covers 21 World Cup tour-
naments (1930-2018) with 7 tables. The description is given only for a subset of columns. Other
columns are self-explanatory. The schema of the database can be found here
1. players: This table has details about the players who participated in FIFA WCs.

2. goals: This table records all goals.

Column Description
The unique ID number for the team that scored the goal. For own
team id goals, this is the team that is awarded the goal, not the team of
the player who scored the own goal
player id The unique ID number for the player who scored the goal
The unique ID number for the team of the player who scored the
player team id
goal

3. matches: This table records all World Cup matches.

Column Description
stage name The stage of the tournament in which the match occurred
home team id The unique ID number for the home team
away team id The unique ID number for the away team
home team score Number of goals scored by the home team
away team score Number of goals scored by the away team
home team score penalties The score of the home team in the penalty shootout
away team score penalties The score of the away team in the penalty shootout

4. penalty kicks: This table records all penalty kicks taken during penalty shootouts. This
table does not include attempted penalty kicks during matches.

Column Description
converted Whether the penalty kick was converted

5. stadiums: This table records all stadiums that have hosted a World Cup match.
6. teams: This table records all teams who have participated in a World Cup match.

7. tournaments: This table records all World Cup tournaments.

2
3 Loading the Dataset
The ’data’ folder provided has 7 csv files. Run ’create table.sql’ (also provided in data folder)
to create the tables. To load the data in the csv files into these tables, use the command: COPY
table-name FROM path/to/file.csv DELIMITER ’,’ CSV HEADER;

Note that you need to load CSV files in some order. It is left as an exercise for you to
identify the right order for loading the data.

4 SQL
4.1 Exercise - 1
Run the following queries, submit the output and describe what each query is doing in the report
1. SELECT COUNT(*) FROM Matches JOIN Tournaments ON Matches.tournament id = Tour-
naments.tournament id AND tournament name = ’2014 FIFA World Cup’
2. SELECT COUNT(*) FROM (SELECT DISTINCT Goals.match id FROM Players JOIN Goals
ON Players.player id = Goals.player id AND Players.family name = ’Mbappé’ AND given name
= ’Kylian’) AS t;
3. SELECT DISTINCT team name FROM Teams JOIN Matches ON (Teams.team id = Matches.home team id
OR Teams.team id = Matches.away team id) AND Matches.stage name = ’final’
4. SELECT COUNT(*) FROM Teams JOIN (SELECT * FROM Matches JOIN Teams ON ((Teams.team id
= Matches.home team id OR Teams.team id = Matches.away team id) AND team name =
’Germany’)) AS t ON ((Teams.team id = t.home team id OR Teams.team id = t.away team id)
AND Teams.team name = ’France’ AND t.stage name != ’group stage’)
5. SELECT DISTINCT player id FROM Goals JOIN (SELECT * FROM Matches JOIN Tourna-
ments ON Matches.tournament id = Tournaments.tournament id AND tournament name
= ’1930 FIFA World Cup’) AS t1 ON Goals.match id = t1.match id AND Goals.own goal =
FALSE

4.2 Exercise - 2
Write SQL Queries for the following
1. Tournaments in which the host country is the winner of the tournament
Output: tournament id, tournament name, year, winner
2. Players who played atleast 4 WCs
Output: player id, family name, given name, count tournaments
3. Number of draw matches Croatia was a part of
Output: num matches
4. Stadium in which the final match of ”1990 FIFA World Cup” tournament was held
Output: stadium name,city name,country name
5. Number of goals scored by Ronaldo (family name: Ronaldo, given name: Cristiano) in all
WCs (Don’t include self goals)
Output: num goals
6. Player with highest number of goals in WCs from 2002 - 2018 (both years inclusive, don’t
include self goals)
Output: player id, family name, given name, num goals

3
7. Team which scored highest number of self goals (lost point to opponent) in last 3 WCs
Output: team id, team name, num self goals

Note: In case of a tie for a query, output all the answers.

You might also like