Sql获取最新的一条信息

来源:互联网 发布:c语言高级编程技巧 编辑:程序博客网 时间:2024/04/30 08:44
 

select 查询的列名 from (
select rank() over(partition by列名 order by
时间 desc)rk,其他列名 from 表名)t
where t.rk=1;

如下面的例子:
Select exception_report_id,exception_type_id,EXCEPTION_QTY
from (select rank() over(partition by exception_report_id order by REPLY_TIME desc) rk,
exception_type_id,exception_report_id,EXCEPTION_QTY
from t_flt_exception_reply) t
where t.rk=1
需要用到一对多查询,取附表的最新记录的,可以用这个函数,效果不错