I was just a little bit confused with the following SQL questions. I'm not sure if I should use any joins or should just use select, count or avg statements. I devised my own question to help me try and understand how to write SQL statements better.
Consider two tables:
CHAMPIONS with columns YEAR, COUNTRY, NAME, ROLE
Listing all players and managers in a world cup winning team. You can assume any person with the same name for the same country in different years is the same person.
GOALS with columns YEAR, COUNTRY, NAME, NUM_GOALS
Listing all goal scorers from any team (ie not just the champions). Non goal-scorers are not included.
So for example entries may look like the below (there are of course many more rows)
CHAMPIONS (~500 rows)
YEAR COUNTRY NAME ROLE
2018 France Didier Deschamps Manager
2018 France Hugo Lloris Goalkeeper
2018 France Paul Pogba Midfielder
2014 Germany Joachim Loew Manager
2014 Germany Mesut Ozil Midfielder
2014 Germany Miroslav Klose Forward
2002 Brazil Da Silva Midfielder
1994 Brazil Da Silva Midfielder
1998 France Didier Deschamps Midfielder
GOALS (~1700 rows)
YEAR COUNTRY NAME NUM_GOALS
2018 England Harry Kane 6
2018 France Antoine Griezmann 4
2014 Argentina Lionel Messi 4
2014 Brazil Fred 1
2010 Germany Thomas Muller 5
2010 Japan Shinji Okazaki 1
1992 England Gary Linekar 6
Questions 1. Write a query to show how many people have won as player and manager? (eg Didier Deschamps)
Q2. Write a query showing how many times each country has won the world cup for countries winning the world cup at least twice.
Q3. Write a query showing all world cup winning players who have never scored a goal.
Q4. Write a query to identify the golden boot winner (highest goal scorer) in each world cup.
I've tried to answer the first question. I think it's right. I'd appreciate it if anyone could help me with the rest. I would be grateful.
What I have tried:
For Question 1 I came up with this:
SELECT COUNT(*) AS CHAMPIONS_ROLE FROM CHAMPIONS WHERE ROLE = 'Manager'AND 'Midfielder';