日期:2014-05-16 浏览次数:20925 次
select * from table1 where (to_char(tranDate,'dd-mm-yyy')||(trim(tranId))||(trim(tranSrlNum)) = ( select max((to_char(tranDate,'dd-mm-yyy')||(trim(tranId))||(trim(tranSrlNum)) ) from table1 where pID = '1234567' )
select * from( select row_number()over(partition by pID order by tranDate desc) row_, t.* from table1) where row_ = 1;
------解决方案--------------------
补充一句,排序条件 order by tranDate desc 我分析只需要这一个条件。
你根据你自己的业务情况,改改吧。
------解决方案--------------------
select * from( select row_number()over(partition by pID order by tranDate desc) row_, t.* from table1 ) where row_ = 1 and pID = '1234567'
------解决方案--------------------
select * from( select row_number()over(partition by pID order by tranDate desc) row_, t.* from table1) where row_ = 1 and pid='' --加条件
------解决方案--------------------
select nt.pid,nt.trandate,nt.tranid,nt.transrlnum,nt.tranAmt from
(select t.pid,t.trandate,t.tranid,t.transrlnum,t.tranAmt,
rank() over(partition by t.pid order by t.trandate desc,t.tranid desc,t.transrlnum desc) r
from table1 t) nt
where nt.r=1 and nt.pid='1234567'
测试通过,给分吧。