Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

SQL exercises on soccer Database: Find the yellow cards received by each country

SQL soccer Database: Joins Exercise-17 with Solution

17. From the following tables, write a SQL query to count the yellow cards received by each country. Return country name and number of yellow cards.

Sample table: soccer_country


Sample table: player_booked


Sample Solution:

SQL Code:

SELECT country_name, COUNT(*)
FROM soccer_country 
JOIN player_booked
ON soccer_country.country_id=player_booked.team_id
GROUP BY country_name
ORDER BY COUNT(*) DESC;

Sample Output:

    country_name     | count
---------------------+-------
 Italy               |    16
 France              |    13
 Portugal            |    13
 Hungary             |    12
 Iceland             |    12
 Wales               |    11
 Germany             |    11
 Romania             |    10
 Albania             |    10
 Poland              |    10
 Republic of Ireland |     9
 Slovakia            |     9
 Belgium             |     9
 Croatia             |     8
 Turkey              |     7
 Austria             |     7
 Northern Ireland    |     6
 Czech Republic      |     5
 Spain               |     5
 Ukraine             |     5
 Switzerland         |     5
 England             |     3
 Sweden              |     3
 Russia              |     2
(24 rows)

Relational Algebra Expression:

Relational Algebra Expression: Find the yellow cards received by each country.

Relational Algebra Tree:

Relational Algebra Tree: Find the yellow cards received by each country.

Practice Online


Sample Database: soccer

soccer database relationship structure

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: From the following tables, write a SQL query to find those teams that scored only one goal to the tournament. Return country_name as "Team", team in the group, goal_for.
Next: From the following tables, write a SQL query to count number of goals that has seen. Return venue name and number of goals.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



SQL: Tips of the Day

SQL Server SELECT into existing table.

INSERT INTO dbo.TABLETWO
SELECT col1, col2
  FROM dbo.TABLEONE
 WHERE col3 LIKE @search_key

This assumes there's only two columns in dbo.TABLETWO - you need to specify the columns otherwise:

INSERT INTO dbo.TABLETWO
  (col1, col2)
SELECT col1, col2
  FROM dbo.TABLEONE
 WHERE col3 LIKE @search_key

Database: SQL Server

Ref: https://bit.ly/3y6tpA3