I have the following two relationships:
Game(id, name, year) Devs(pid, gid, role)
Where Game.id is the primary key and where Devs .gid is the foreign key for Game.id.
I want to write an SQL query that will find the game with the most people who worked on this game. I wrote the following query:
SELECT Game.name, count(DISTINCT Devs.pid) FROM Game, Devs WHERE Devs.gid=Game.id GROUP BY Devs.gid, Game.name ORDER BY count(Devs.pid) DESC;
This query fulfills my task in the sense that it returns all games in the ratio, sorted by the number of people who worked on each game, but I am trying to modify this query so that it does two things. Firstly, he should return the game only to the majority of people who worked on it, and two, if two games work on them, on which an equal number of people work, it should return both of these games. I know that if I replace the top line as follows:
SELECT TOP 1 Game.name, count(DISTINCT Devs.pid)
Then he fulfills my first goal, but if there are two games that have the largest number of people who worked on them, then she returns only one of these games. How can I modify this query to return all games with the most people who worked on it?
max sql
Kyle
source share