2013-10-10 48 views
0
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 

我需要檢索第4行,我已經寫了部分代碼,請幫助我的另一半。sql查詢 - Oracle數據庫

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.............. 

請幫助我在哪裏應該是通用的,而不是行特定的caluse。我認爲它應該充滿第n個最大的概念,但不知道。

+3

**試着寫自己的東西**,然後如果它不工作,告訴我們具體你做了什麼,所以我們可以幫助你。你開始吧,我們幫忙。我們不會爲你寫信。向我們展示您嘗試過的實際代碼,然後我們可以從那裏幫助您。如果你只是先嚐試​​一下,你很可能會接近答案。 –

+0

謝謝安迪。我曾嘗試在where子句中 - – user2865419

+0

其中(n-1)=(選擇計數(來自psjob1的distinct(a1.effseq),其中a2.effseq> a1.effseq),但該代碼在邏輯上不合適 – user2865419

回答

1

在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**; 

在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 ..... ) 
+0

我不知道如何聲明不會在Oracle上工作可以接受作爲一個問題的答案,在主題 –

+0

說「Oracle」它是作爲一個SQL,所以我把這一個作爲答案 – SSP

+0

將編輯根據oracle語法 – SSP