Skip to content

Commit 391fdbf

Browse files
Add queries sh
1 parent fe63b7b commit 391fdbf

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

queries.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#! /bin/bash
2+
3+
PSQL="psql --username=freecodecamp --dbname=worldcup --no-align --tuples-only -c"
4+
5+
# Do not change code above this line. Use the PSQL variable above to query your database.
6+
7+
echo -e "\nTotal number of goals in all games from winning teams:"
8+
echo "$($PSQL "SELECT SUM(winner_goals) FROM games")"
9+
10+
echo -e "\nTotal number of goals in all games from both teams combined:"
11+
echo "$($PSQL "SELECT SUM(winner_goals + opponent_goals) FROM games")"
12+
13+
echo -e "\nAverage number of goals in all games from the winning teams:"
14+
echo "$($PSQL "SELECT AVG(winner_goals) FROM games")"
15+
16+
echo -e "\nAverage number of goals in all games from the winning teams rounded to two decimal places:"
17+
echo "$($PSQL "SELECT ROUND(AVG(winner_goals), 2) FROM games")"
18+
19+
echo -e "\nAverage number of goals in all games from both teams:"
20+
echo "$($PSQL "SELECT AVG(winner_goals + opponent_goals) FROM games")"
21+
22+
echo -e "\nMost goals scored in a single game by one team:"
23+
echo "$($PSQL "SELECT MAX(winner_goals) FROM games")"
24+
25+
echo -e "\nNumber of games where the winning team scored more than two goals:"
26+
echo "$($PSQL "SELECT COUNT(*) FROM games WHERE winner_goals > 2")"
27+
28+
echo -e "\nWinner of the 2018 tournament team name:"
29+
echo "$($PSQL "SELECT name FROM teams WHERE team_id = (SELECT winner_id FROM games WHERE round = 'Final' AND year = 2018)")"
30+
31+
echo -e "\nList of teams who played in the 2014 'Eighth-Final' round:"
32+
echo "$($PSQL "SELECT DISTINCT teams.name FROM teams JOIN games ON teams.team_id IN (games.winner_id, games.opponent_id) WHERE games.year = 2014 AND games.round = 'Eighth-Final'")"
33+
34+
echo -e "\nList of unique winning team names in the whole data set:"
35+
echo "$($PSQL "SELECT DISTINCT teams.name FROM teams JOIN games ON teams.team_id = games.winner_id ORDER BY name ASC")"
36+
37+
echo -e "\nYear and team name of all the champions:"
38+
echo "$($PSQL "SELECT games.year, teams.name FROM teams JOIN games ON teams.team_id = games.winner_id WHERE games.round = 'Final' ORDER BY year ASC")"
39+
40+
echo -e "\nList of teams that start with 'Co':"
41+
echo "$($PSQL "SELECT name FROM teams WHERE name LIKE 'Co%'")"

0 commit comments

Comments
 (0)