Trying to solve some queries from sql zoo to practice sql skills
I have a table nobel with columns (year, subject, winner) which have information on the people who have earned noble prizes in a given year for a given subject.
So I assume the primary key to be composite of (year, subject, winner).
The problem I am trying to solve is: Show winners who have won more than one subject.
The output of the SQL query should have just one column with the winner names.
I feel that I should be using group by and using having(count(winner)) >1. But I think I need to group by by subject and that’s where my problem is.
I am not looking for a query. If you can provide me with more logic than query that would help. Also do not worry about the database it needs to be implemented on. I am just practicing these questions.
This should give you people who won on multiple different subjects in any number of years:
For a specific year, just add
WHERE year = <whatever>(orGROUP BY yearfor all years), though no person in history won a Nobel for two subjects in a single year – but who knows what future brings 😉