World Cup Database - Build a World Cup Database

Tell us what’s happening:

Completed this script and yet it still won’t pass for some reason. The expected output matches the output that I get for this.

Your code so far

#! /bin/bash

PSQL="psql --username=freecodecamp --dbname=worldcup --no-align --tuples-only -c"

# Do not change code above this line. Use the PSQL variable above to query your database.

echo -e "\nTotal number of goals in all games from winning teams:"

echo "$($PSQL "SELECT SUM(winner_goals) FROM games")"

echo -e "\nTotal number of goals in all games from both teams combined:"

echo "$($PSQL "SELECT SUM(winner_goals + opponent_goals) from games")"

echo -e "\nAverage number of goals in all games from the winning teams:"

echo "$($PSQL "SELECT AVG(winner_goals) from games")"

echo -e "\nAverage number of goals in all games from the winning teams rounded to two decimal place:"

echo "$($PSQL "SELECT ROUND(AVG(winner_goals), 2) FROM games")"

echo -e "\nAverage number of goals in all games from both teams:"

echo "$($PSQL "SELECT AVG(winner_goals + opponent_goals) from games")"

echo -e "\nMost goals scored in a single game by one team:"

echo "$($PSQL "SELECT MAX(winner_goals) from games")"

echo -e "\nNumber of games where the winning team scored more than two goals:"

echo "$($PSQL "SELECT COUNT(game_id) from games where winner_goals > 2")"

echo -e "\nWinner of the 2018 tournament team name:"

echo "$($PSQL "SELECT name FROM teams FULL JOIN games ON teams.team_id=games.winner_id WHERE year=2018 AND round='Final'")"

echo -e "\nList of teams who played in the 2014 'Eighth-Final' round:"

echo "$($PSQL "SELECT name FROM teams INNER JOIN games ON teams.team_id=games.winner_id OR teams.team_id=games.opponent_id WHERE year=2014 AND round='Eighth-Final' ORDER BY name")"

echo -e "\nList of unique winning team names in the whole data set:"

echo "$($PSQL "SELECT DISTINCT(name) FROM teams INNER JOIN games ON teams.team_id=games.winner_id ORDER BY name")"

echo -e "\nYear and team name of all the champions:"

echo "$($PSQL "SELECT year, name FROM games FULL JOIN teams ON games.winner_id=teams.team_id WHERE winner_id IS NOT NULL AND round='Final' GROUP BY year, name ORDER BY year")"

echo -e "\nList of teams that start with 'Co':"

echo "$($PSQL "SELECT name FROM teams WHERE name LIKE 'Co%' ORDER BY name")"

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 OPR/115.0.0.0

Challenge Information:

World Cup Database - Build a World Cup Database

Hi @SoFran ,

Thanks for posting.

We need a bit more information to help you? From your request it is not clear to me how you are calling those commands.

It appears that the exercise consists in modifying the queries.sh file and then running the queries.sh file from your terminal. Did you already try that? If not, what were you trying to do?

Then, after you clarify to us how you were running the code, maybe if you can be more specific regarding this comment?

Not knowing still your problem, I think this commented expression

echo “$($PSQL “SELECT SUM(winner_goals) FROM games”)”

and other similar commented expressions in the queries.sh file should be things that you would like to check in more depth?

Finally, if getting an error, perhaps adding a copy of the first lines will be enough to start (I don’t know yet)? Please don’t include anything you might consider personal in that copy, we only want to see full or partial copies of the error.

Hope this helps?

Hi @SoFran

Please post the output.

Happy coding

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

Hi,

Here is the output that I get.

Total number of goals in all games from winning teams:
68

Total number of goals in all games from both teams combined:
90

Average number of goals in all games from the winning teams:
2.1250000000000000

Average number of goals in all games from the winning teams rounded to two decimal place:
2.13

Average number of goals in all games from both teams:
2.8125000000000000

Most goals scored in a single game by one team:
7

Number of games where the winning team scored more than two goals:
6

Winner of the 2018 tournament team name:
France

List of teams who played in the 2014 'Eighth-Final' round:
Algeria
Argentina
Belgium
Brazil
Chile
Colombia
Costa Rica
France
Germany
Greece
Mexico
Netherlands
Nigeria
Switzerland
United States
Uruguay

List of unique winning team names in the whole data set:
Argentina
Belgium
Brazil
Colombia
Costa Rica
Croatia
England
France
Germany
Netherlands
Russia
Sweden
Uruguay

Year and team name of all the champions:
2014|Germany
2018|France

List of teams that start with 'Co':
Colombia
Costa Rica

Hi @SoFran

Expected output:

Your output:

Happy coding

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.