MySQL Select rows on first occurrence of each unique value

后端 未结 5 1160
迷失自我
迷失自我 2020-12-08 04:06

Let\'s say you have the following table (the column of interest here is cid):

+-----+-------+-------+-------+---------------------+-------------         


        
5条回答
  •  臣服心动
    2020-12-08 04:55

    You could use a filtering join:

    select  *
    from    (
            select  cid
            ,       min(time) as min_time
            from    YourTable
            group by
                    cid
            ) filter
    join    YourTable yt
    on      filter.cid = yt.cid
            and filter.min_time = yt.time
    

提交回复
热议问题