MySQL query, MAX() + GROUP BY

后端 未结 7 859
不思量自难忘°
不思量自难忘° 2020-11-27 05:16

Daft SQL question. I have a table like so (\'pid\' is auto-increment primary col)

CREATE TABLE theTable (
    `pid` INT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
          


        
7条回答
  •  抹茶落季
    2020-11-27 05:47

    select *
    from (
        select `pid`, `timestamp`, `cost`, `rid`
        from theTable 
        order by `timestamp` desc
    ) as mynewtable
    group by mynewtable.`rid`
    order by mynewtable.`timestamp`
    

    Hope I helped !

提交回复
热议问题