SQL Joins exercises on soccer Database: Find the number of players booked for each team
SQL soccer Database: Joins Exercise-43 with Solution
43. From the following tables, write a SQL query to find the number of players booked for each team. Return country name, number of players booked.
Sample table: soccer_country
Sample table: player_booked
Sample Solution:
SQL Code:
SELECT a.country_name,COUNT(b.*) Booked
FROM soccer_country a
JOIN player_booked b ON a.country_id=b.team_id
GROUP BY a.country_name
ORDER BY Booked DESC;
Sample Output:
country_name | booked ---------------------+-------- Italy | 16 France | 13 Portugal | 13 Iceland | 12 Hungary | 12 Germany | 11 Wales | 11 Romania | 10 Poland | 10 Albania | 10 Belgium | 9 Slovakia | 9 Republic of Ireland | 9 Croatia | 8 Austria | 7 Turkey | 7 Northern Ireland | 6 Ukraine | 5 Czech Republic | 5 Spain | 5 Switzerland | 5 England | 3 Sweden | 3 Russia | 2 (24 rows)
Practice Online
Sample Database: soccer
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: From the following tables, write a SQL query to count the players who booked the most number of times. Return player name, number of players who booked most number of times.
Next: From the following tables, write a SQL query to find those matches where most number of cards shown. Return match number, number of cards shown.
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
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework