oracle查询的问题: 有五个名字,每个名字下办理的业务时间不同,怎么查询出每个名字办理距离现在时间最近的一条业务?
select 名字,max(业务时间)
from
xxxxx
where 名字 in (五个名字)
group by 名字
order by 1
/
表名:T1
列-名字:name
列-业务时间:time
--查询每个名字下办理业务时间最近的一条记录
select * from T1 where (name,time) in select (name,max(time) from T1 group by name);
这个应该用开窗函数做分组排序
select t.* from (select row_number() over(partition by 名字 order by 业务时间 desc) rn, t.* from t where 名字 in ('A','B','C','D','E')) t where rn = 1