848525 wrote:You can use analytic functions like ROW_NUMBER, RANK, DENSE_RANK.
how to fetch the last two inserted rows in each dept.
i wrote the following query but it is taking so much of time but not giving the output.can anyone suggest.
select * from rcpt_tran where rcpt_dt in(
select MAX(rcpt_dt) from rcpt_tran
WHERE rcpt_dt NOT IN (select MAX(rcpt_dt) from rcpt_tran group by msno
) group by msno
select MAX(rcpt_dt) from rcpt_tran group by msno)
Edited by: Karthick_Arp on Jan 2, 2013 1:28 AM
select * from ( select t.*, rank() over(partition by msno order by rcpt_dt desc) rk from rcpt_tran t ) where rk <= 2