MySQL find top results for each group

前端 未结 2 1423
無奈伤痛
無奈伤痛 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:50

         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 order by result DESC;
    

提交回复
热议问题