表名:alarminfo
agentname arrivetime
aaaa 2016/1/16 8:03:13
aaaa 2016/1/16 11:31:36
aaaa 2016/1/20 3:28:46
bbbb 2016/1/16 11:11:58
bbbb 2016/1/20 3:28:49
bbbb 2015/9/8 10:41:40
那应该怎么查这些记录中字段的最新时间的一条记录呢
2 个解决方案
#1
select * from
(select t.*,row_number()over(partition by agentname order by arrivetime desc) rn from alarminfo t) where rn=1
(select t.*,row_number()over(partition by agentname order by arrivetime desc) rn from alarminfo t) where rn=1
#2
标准答案:
select agentname,arrivetime
from (select agentname,arrivetime,
row_number()over(partition by agentname order by arrivetime desc) rn
from alarminfo
)
where rn=1;
#1
select * from
(select t.*,row_number()over(partition by agentname order by arrivetime desc) rn from alarminfo t) where rn=1
(select t.*,row_number()over(partition by agentname order by arrivetime desc) rn from alarminfo t) where rn=1
#2
标准答案:
select agentname,arrivetime
from (select agentname,arrivetime,
row_number()over(partition by agentname order by arrivetime desc) rn
from alarminfo
)
where rn=1;