2013-04-14 76 views
0

我有一個關於如何與rownum正常工作的問題。我知道如何提取select的前n行,但我的傢伙是如何做到這一點,但以rownumber 50.000開頭,以及如何提取範圍內的行。從數字開始獲取rownums輸出

這是我的查詢,當我試圖從50.000行提取直到最後時,SQL Developer顯示一個空的結果。

SELECT amy_fields 
FROM p1detail d 
INNER JOIN p2 p 
ON (d.p1tid = p.p1id) 
INNER JOIN p1lot l 
ON (p.paiementlotid = l.p1lotid) 
INNER JOIN prmstatus s 
ON (d.status = s.id) 
WHERE s.langue = 0 
AND longtodate (p.datecompta) >= '15/01/2013' 
AND longtodate (p.datecompta) <= '15/03/2013' 
AND d.emetteurid in ( 
    select e.emetteurid from emetteur e 
    where e.grpemetteurid in ('DPP','DEDCT') 
) 
AND ROWNUM > 50000 
ORDER BY d.datecompta; 

回答

1

也許這可以幫助你:

WITH records as (
    SELECT ROW_NUMBER() over(order by d.p1tid) as Num,amy_fields 
    FROM p1detail d 
    INNER JOIN p2 p 
    ON (d.p1tid = p.p1id) 
    INNER JOIN p1lot l 
    ON (p.paiementlotid = l.p1lotid) 
    INNER JOIN prmstatus s 
    ON (d.status = s.id) 
    WHERE s.langue = 0 
    AND longtodate (p.datecompta) >= '15/01/2013' 
    AND longtodate (p.datecompta) <= '15/03/2013' 
    AND d.emetteurid in ( 
     select e.emetteurid from emetteur e 
     where e.grpemetteurid in ('DPP','DEDCT') 
    ) 
)select * from records 
where Num between 2 and 6 --'(or > 50000)' 
ORDER BY records.datecompta; 
+0

喜歡這裏使用解析函數。替代方法是在子查詢中排序,將rownum附加到另一箇中,然後只篩選第一個「N」結果。豎起大拇指。 – haki

+1

請使用代碼塊代碼,而不是塊引用(http://stackoverflow.com/editing-help#code) – Mat

+0

感謝您的意見...亞麻墊哈哈謝謝你的朋友... – Fuad

0

的東西嘗試像

select amyfields from (
    select amy_fields, rownum rn from ( 
     SELECT amy_fields 
     FROM p1detail d 
     INNER JOIN p2 p 
     ON (d.p1tid = p.p1id) 
     INNER JOIN p1lot l 
     ON (p.paiementlotid = l.p1lotid) 
     INNER JOIN prmstatus s 
     ON (d.status = s.id) 
     WHERE s.langue = 0 
     AND longtodate (p.datecompta) >= '15/01/2013' 
     AND longtodate (p.datecompta) <= '15/03/2013' 
     AND d.emetteurid in ( 
     select e.emetteurid from emetteur e 
     where e.grpemetteurid in ('DPP','DEDCT') 
     ORDER BY d.datecompta 
) where rownum < :upper_limit 
) 
where rn > :lower_limit