显示每个员工的最新修改记录

时间:2017-07-31 07:07:58

标签: sql

emp表就像这样

id     Name              Date Modified
1     Ram              2017-01-05
2     Kishore          2017-02-04
3    John             2017-04-22
1   Ram K             2017-04-25
1   Ram Kumar         2017-05-01
2   Kishore Babu      2017-05-05
3   John B            2017-06-01

1 个答案:

答案 0 :(得分:0)

假设您正在使用支持窗口函数的合理row_number应该可以解决问题:

SELECT id, name, date_modified
FROM   (SELECT id, name, date_modified,
               ROW_NUMBER() OVER (PARTITION BY id ORDER BY date_modified DESC) rn
        FROM   emp) t
WHERE  rn = 1