MySQL find top results for each group

前端 未结 2 1422
無奈伤痛
無奈伤痛 2021-01-28 18:21

I have searched a lot, but I can\'t find an answer or something near.

I have a table like this:

id              int(11) NO  PRI     auto_increment
attri         


        
2条回答
  •  星月不相逢
    2021-01-28 18:51

    SELECT  attribute_id, result
    FROM    TableName a
    WHERE 
            (
                SELECT  COUNT(*) 
                FROM    TableName b
                WHERE   a.attribute_id = b.attribute_id 
                        AND a.result <= b.result
            ) <= 5
    
    • SQLFiddle Demo

提交回复
热议问题