Database: wta_1

Question: Find the average age of losers and winners of all matches.
SQL: SELECT avg(loser_age) ,  avg(winner_age) FROM matches

Question: Find the name of tourney that has more than 10 matches.
SQL: SELECT tourney_name FROM matches GROUP BY tourney_name HAVING count(*)  >  10

Question: List the names of all winners who played in both 2013 and 2016.
SQL: SELECT winner_name FROM matches WHERE YEAR  =  2013 INTERSECT SELECT winner_name FROM matches WHERE YEAR  =  2016

Question: List the number of all matches who played in years of 2013 or 2016.
SQL: SELECT count(*) FROM matches WHERE YEAR  =  2013 OR YEAR  =  2016

Question: What are the country code and first name of the players who won in both tourney WTA Championships and Australian Open?
SQL: SELECT T1.country_code ,  T1.first_name FROM players AS T1 JOIN matches AS T2 ON T1.player_id  =  T2.winner_id WHERE T2.tourney_name  =  'WTA Championships' INTERSECT SELECT T1.country_code ,  T1.first_name FROM players AS T1 JOIN matches AS T2 ON T1.player_id  =  T2.winner_id WHERE T2.tourney_name  =  'Australian Open'

Question: Find the first name and country code of the oldest player.
SQL: SELECT first_name ,  country_code FROM players ORDER BY birth_date LIMIT 1

Question: List the first and last name of all players who are left / L hand in the order of birth date.
SQL: SELECT first_name ,  last_name FROM players WHERE hand  =  'L' ORDER BY birth_date

Question: Find the first name and country code of the player who did the most number of tours.
SQL: SELECT T1.country_code ,  T1.first_name FROM players AS T1 JOIN rankings AS T2 ON T1.player_id  =  T2.player_id ORDER BY T2.tours DESC LIMIT 1

Question: Find the year that has the most number of matches.
SQL: SELECT YEAR FROM matches GROUP BY YEAR ORDER BY count(*) DESC LIMIT 1

Question: Find the name and rank points of the winner who won the most times.
SQL: SELECT winner_name ,  winner_rank_points FROM matches GROUP BY winner_name ORDER BY count(*) DESC LIMIT 1

Question: Find the name of the winner who has the highest rank points and participated in the Australian Open tourney.
SQL: SELECT winner_name FROM matches WHERE tourney_name  =  'Australian Open' ORDER BY winner_rank_points DESC LIMIT 1

Question: find the names of loser and winner who played in the match with greatest number of minutes.
SQL: SELECT winner_name ,  loser_name FROM matches ORDER BY minutes DESC LIMIT 1

Question: Find the average ranking for each player and their first name.
SQL: SELECT avg(ranking) ,  T1.first_name FROM players AS T1 JOIN rankings AS T2 ON T1.player_id  =  T2.player_id GROUP BY T1.first_name

Question: Find the total ranking points for each player and their first name.
SQL: SELECT sum(ranking_points) ,  T1.first_name FROM players AS T1 JOIN rankings AS T2 ON T1.player_id  =  T2.player_id GROUP BY T1.first_name

Question: find the code of the country where has the greatest number of players.
SQL: SELECT country_code FROM players GROUP BY country_code ORDER BY count(*) DESC LIMIT 1

Question: Find the codes of countries that have more than 50 players.
SQL: SELECT country_code FROM players GROUP BY country_code HAVING count(*)  >  50