-----------------------------------------------------------------
SWO11764 已派单 2014-09-19 12:05:34.000
SWO11764 召回 2014-09-19 12:45:21.000
SWO11764 已派单 2014-09-19 12:45:41.000
SWO11764 处理中 2014-09-19 12:45:47.000
SWO11764 退单 2014-09-19 12:45:51.000
SWO11764 已派单 2014-09-19 12:46:44.000
SWO11764 处理中 2014-09-19 12:46:48.000
SWO11764 退单 2014-09-19 12:47:22.000
SWO11764 已派单 2014-09-20 00:07:38.000
这是记录表中的某一个ID的多条记录,我想取得最后一次修改时间的状态,用SQL怎么写出来啊?
求指导!
4 个解决方案
#1
select * from tablename as a
where max(logdate)
(select max(logdate) from tablename as b where a.id=b.id)
where max(logdate)
(select max(logdate) from tablename as b where a.id=b.id)
#2
少个=号 呵呵
#3
select ID, OrderState, LogDate from (
select * ,row_number() over(partition by ID order by LogDate desc) as rID from tablename
) a where rID=1
select * ,row_number() over(partition by ID order by LogDate desc) as rID from tablename
) a where rID=1
#4
其实这个子查询效率比ROW_nUMBER效率高
#1
select * from tablename as a
where max(logdate)
(select max(logdate) from tablename as b where a.id=b.id)
where max(logdate)
(select max(logdate) from tablename as b where a.id=b.id)
#2
少个=号 呵呵
#3
select ID, OrderState, LogDate from (
select * ,row_number() over(partition by ID order by LogDate desc) as rID from tablename
) a where rID=1
select * ,row_number() over(partition by ID order by LogDate desc) as rID from tablename
) a where rID=1
#4
其实这个子查询效率比ROW_nUMBER效率高