I have a (simplified) table named source
:
game_index int,
rating int,
attributes varchar(42)
And now I'm looking for a select command, that extracts the top 3 records (rating
) for each game (game_index
). I want to store the results into another table (called max
, same table layout). So multiple SQL commands are possible.
Without game_index
it is easy:
INSERT INTO max
SELECT * FROM source
ORDER BY rating DESC LIMIT 3
How to combine it with GROUP BY game_index
?
Any ideas?
Additional table members or temporary tables are possible.