2013-04-14 74 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