SELECT only latest record of an ID from given rows

前端 未结 4 407
生来不讨喜
生来不讨喜 2021-01-26 01:58

I have this table shown below...How do I select only the latest data of the id based on changeno?

+----+--------------+------------+--------+
| id |  data   | ch         


        
4条回答
  •  长情又很酷
    2021-01-26 02:24

    You want to use row_number() for this:

    select id, data, changeno
    from (SELECT t.*,
                 row_number() over (partition by id order by changeno desc) as seqnum
          FROM Table1 t
         ) t
    where seqnum = 1;
    

提交回复
热议问题