SQL Joins exercises on soccer Database: Find the players along with their team booked number of times in the tournament
SQL soccer Database: Joins Exercise-41 with Solution
41. From the following tables, write a SQL query to find the players along with their team booked number of times in the tournament. Show the result according to the team and number of times booked in descending order. Return country name, player name, and team booked number of times.
Sample table: soccer_country
Sample table: player_booked
Sample table: player_mast
Sample Solution:
SQL Code:
SELECT a.country_name,c.player_name,COUNT(b.*) Booked
FROM soccer_country a
JOIN player_booked b ON a.country_id=b.team_id
JOIN player_mast c ON b.player_id=c.player_id
GROUP BY a.country_name,c.player_name
ORDER BY a.country_name,Booked DESC;
Sample Output:
country_name | player_name | booked ---------------------+-------------------------+-------- Albania | Lorik Cana | 2 Albania | Burim Kukeli | 2 Albania | Ledian Memushaj | 1 Albania | Mergim Mavraj | 1 Albania | Migjen Basha | 1 Albania | Elseid Hysaj | 1 Albania | Amir Abrashi | 1 Albania | Ergys Kace | 1 Austria | Aleksandar Dragovic | 2 Austria | Marc Janko | 1 Austria | Martin Harnik | 1 Austria | Alessandro Schopf | 1 Austria | Christian Fuchs | 1 Austria | Martin Hinteregger | 1 Belgium | Thomas Vermaelen | 2 Belgium | Marouane Fellaini | 2 Belgium | Michy Batshuayi | 1 Belgium | Thomas Meunier | 1 Belgium | Axel Witsel | 1 Belgium | Toby Alderweireld | 1 Belgium | Jan Vertonghen | 1 Croatia | Milan Badelj | 1 Croatia | Sime Vrsaljko | 1 Croatia | Marko Rog | 1 Croatia | Marcelo Brozovic | 1 Croatia | Ivan PeriSic | 1 Croatia | Ivan Strinic | 1 Croatia | Darijo Srna | 1 Croatia | Domagoj Vida | 1 -------- Turkey | Hakan Balta | 2 Turkey | Cenk Tosun | 1 Turkey | Volkan Sen | 1 Turkey | Burak Yilmaz | 1 Turkey | Ozan Tufan | 1 Turkey | Ismail Koybasi | 1 Ukraine | Ruslan Rotan | 1 Ukraine | Olexandr Kucher | 1 Ukraine | Yevhen Konoplyanka | 1 Ukraine | Serhiy Sydorchuk | 1 Ukraine | Yevhen Seleznyov | 1 Wales | Ben Davies | 2 Wales | Aaron Ramsey | 2 Wales | James Chester | 2 Wales | Chris Gunter | 1 Wales | Sam Vokes | 1 Wales | Joe Allen | 1 Wales | Neil Taylor | 1 Wales | Gareth Bale | 1 (167 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 find the number of captains who was also the goalkeeper. Return number of captains.
Next: 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.
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