empid emplrcd effdt effsq
101 #1 2/1/99 0
101 #1 3/1/13 1
101 #1 23/3/13 1
101 #1 22/6/13 2
102 #2 20/6/91 1
I need to retrieve row 4, and I have written a partial code, please help me with the other half.
select a*
from Ps_Job a
where a.empid = '101'
and a.emprcd ='#1'
and a.effdt = (select max(a1.effdt) from Psjob1) where...............
and a.effseq = (Select max(a2.effseq) from Ps_job2)
where..............
Please help me with the where caluse which should be generic and not row specific. i think it should be filled with nth max concept but not sure.
Adriaan Stander
167k32 gold badges293 silver badges287 bronze badges
-
3Try writing something yourself and then if it doesn't work, show us specifically what you did so we can help you along. You start it, we help. We don't write it for you. Show us the actual code that you've tried and then we can help you from there. Chances are you'll get pretty close to the answer if you just try it yourself first.Andy Lester– Andy Lester2013年10月10日 04:20:03 +00:00Commented Oct 10, 2013 at 4:20
-
Thanks Andy. I have tried in where clause -user2865419– user28654192013年10月10日 04:28:36 +00:00Commented Oct 10, 2013 at 4:28
-
where (n-1) = (select count (distinct(a1.effseq) from psjob1 where a2.effseq > a1.effseq ), but the code doesn't logically fit.user2865419– user28654192013年10月10日 04:30:30 +00:00Commented Oct 10, 2013 at 4:30
-
@user2865419 on what conditions you want to get 4th row? based on max date and sq?Vishwanath Dalvi– Vishwanath Dalvi2013年10月10日 04:57:04 +00:00Commented Oct 10, 2013 at 4:57
-
is ur requirement to get last row of same specific ID ?SSP– SSP2013年10月10日 05:11:12 +00:00Commented Oct 10, 2013 at 5:11
1 Answer 1
In oracle
select *
from
(select a* from Ps_Job a
where a.empid = '101'
and a.emprcd ='#1'
and a.effdt = (select max(a1.effdt) from Psjob1) where ...
and a.effseq = (Select max(a2.effseq) from Ps_job2)
where ..... )
where ROWNUM == **The line number what you want to get**;
In sql
SELECT * from Ps_Job LIMIT 3,1where(
select a* from Ps_Job a
where a.empid = '101'
and a.emprcd ='#1'
and a.effdt = (select max(a1.effdt) from Psjob1) where ...
and a.effseq = (Select max(a2.effseq) from Ps_job2)
where ..... )
answered Oct 10, 2013 at 5:45
Sign up to request clarification or add additional context in comments.
3 Comments
SSP
it's taged as a sql so i put this one as answer
lang-sql