mysql - sql - select amount from each type -



mysql - sql - select amount from each type -

i want select 10 names table "games" each game type.

for example: 10 rpg games, 10 action games, 10 mmo games...

the problem query take lot of resources, wondering if has thought write query in improve way:

select name games thisgame (select count(1) games games.game_id = thisgame.game_id , games.type > thisgame.type) <= 9

one way fast variable trick. relies on mysql specific syntax imitate window function. example, retrieve 2 games per type:

select s.name , s.type ( select * , (@rn := if(@cur=type, @rn+1, 1)) rn , @cur := type games bring together (select @cur := '') order type ) s rn <= 2

live illustration @ sql fiddle.

mysql sql resources

Comments

Popular posts from this blog

javascript - mongodb won't find my schema method in nested container -

Hibernate criteria by a list of natural ids -

ios - Lagging ScrollView with UIWebview inside -