当前位置: 代码迷 >> Oracle开发 >> oracle从查询结果中分页!求解答,该如何处理
  详细解决方案

oracle从查询结果中分页!求解答,该如何处理

热度:103   发布时间:2016-04-24 06:38:39.0
oracle从查询结果中分页!!求解答
select t.* from (

select rownum as  rn, a.emp_id,a.service_date,a.customer_id,a.service_type from
(select s.PROCESSER_ID as emp_id,to_char(s.done_date,'yy-mm-dd') as service_date,s.customer_id ,s.customer_tax_id,decode(s.service_type_id,1,'维护',4,'回访') as service_type
    from EMP_SERVICE2014 s
    where  s.service_type_id in(1,4)
    and s.processer_id=216491 

    UNION all

    select p.fee as emp_id,to_char(p.visit_end_date,'yy-mm-dd') as service_date,p.customer_id,p.customer_tax_id,'回访' as service_type
    from EMP_PV2014 p
    where p.fee=216491 
    and not exists (select 1 from emp_service2014 s where p.customer_id=s.customer_id and  to_char(p.visit_end_date,'yyyy-mm-dd')=to_char(s.done_date,'yyyy-mm-dd')and s.service_type_id in(1,4))
    ) a
    
    where rn<50
)t    
    where t.rn>10

请问这样写分页为什么不行啊????我的目的是 从查询的结果集a 中实现分页!!
求大神们解答!
------解决方案--------------------
引用:
提示 rn 标示符无效,这是怎么回事啊



select t.*
  from (select rownum as rn,
               a.emp_id,
               a.service_date,
               a.customer_id,
               a.service_type
          from (select s.PROCESSER_ID as emp_id,
                       to_char(s.done_date, 'yy-mm-dd') as service_date,
                       s.customer_id,
                       s.customer_tax_id,
                       decode(s.service_type_id, 1, '维护', 4, '回访') as service_type
                  from EMP_SERVICE2014 s
                 where s.service_type_id in (1, 4)
                   and s.processer_id = 216491
                
                UNION all
                
                select p.fee as emp_id,
                       to_char(p.visit_end_date, 'yy-mm-dd') as service_date,
                       p.customer_id,
                       p.customer_tax_id,
                       '回访' as service_type
                  from EMP_PV2014 p
                 where p.fee = 216491
                   and not exists
                 (select 1
                          from emp_service2014 s
                         where p.customer_id = s.customer_id
                           and to_char(p.visit_end_date, 'yyyy-mm-dd') =
                               to_char(s.done_date, 'yyyy-mm-dd')
  相关解决方案