17,377
社区成员
发帖
与我相关
我的任务
分享
select distinct * from tbl
where [操作时间] in (SELECT max([操作时间]) from tbl(nolock) group by [设备id])
select * from (select t.*,row_number() over(partition by sbid order by operdate desc) num from tab t) where num=1
SELECT * FROM TAB
WHERE (设备id,操作时间) IN (
SELECT 设备id,min(操作时间) from tab group by 设备id
)
with temp as(
select 1 id,1 设备id, to_date('2009-09-09','yyyy-mm-dd') 操作时间 from dual
union all
select 2 id,2 设备id, to_date('2009-09-10','yyyy-mm-dd') 操作时间 from dual
union all
select 3 id,1 设备id, to_date('2010-09-01','yyyy-mm-dd') 操作时间 from dual
union all
select 4 id,2 设备id, to_date('2010-01-01','yyyy-mm-dd') 操作时间 from dual
union all
select 5 id,2 设备id, to_date('2010-01-02','yyyy-mm-dd') 操作时间 from dual
)
select max(id) id,设备id,max(操作时间) 操作时间 from temp group by 设备id