Select highest 3 scores in each day for every user

后端 未结 2 1408
清歌不尽
清歌不尽 2021-01-07 02:28

I have a MYSQL table like this:

  id |  userid  |  score  |      datestamp      |
-----------------------------------------------------
  1  |    1     |   5         


        
2条回答
  •  北荒
    北荒 (楼主)
    2021-01-07 03:21

    SELECT 
        * 
    FROM
        table1
    LEFT JOIN 
        (SELECT * FROM table1 ORDER BY score LIMIT 3) as lr on DATE(lr.datestamp) = DATE(table1.datastamp)
    GROUP BY 
        datestamp   
    

提交回复
热议问题