繁体   English   中英

Oracle条件限制SQL查询

[英]Oracle condition to limit sql query

我有此sql用于oracle数据库。 如何写条件以获取5到30之间的数据? 基于sql的值,我想使用分页在php中创建一个datagrid。

"select c.case_id as NGM_ID,   
       s.NE_PRIORITAET as NE_PRIO,
       case substr(s.NE_ID, 2,1)
         when '0' then 'Zentrale'
         when '1' then 'Nord'
         when '2' then 'Nord' 
         when '3' then 'Ost'
         when '4' then 'Ost'
         when '5' then 'Mitte'
         when '6' then 'West'
         when '7' then 'Süd'
         when '8' then 'Mitte'
         when '9' then 'Süd'
         else          'Error'
       end as REGION,         
       c.STATUS_NGM as NGM_STATUS,
       s.AUFTRAG as AUFTRAG,
       s.NE_ID as NE_ID,
       s.STATUS as SAP_STATUS,
       substr(to_timestamp(to_char(Sysdate, 'YY/MM/DD HH24:MI:SS'), 'YY/MM/DD HH24:MI:SS') - to_timestamp(to_char(s.CREATION_TIME, 'YY/MM/DD HH24:MI:SS'), 'YY/MM/DD HH24:MI:SS'), 8,12) as DIFF_BEGINN_SAP_ENDE,
      case trim(s.KATEGORIE)
         when '1' then 'INSLA'
         when '2' then 'OUTSLA'
         else          s.KATEGORIE
       end as SLA,
       to_char(c.CREATION_TIME, 'YY/MM/DD HH24:MI:SS')
        as NGM_CREATION_TIME,
       case s.NE_PRIORITAET
         when 'A' then substr(to_char((to_timestamp(to_char((Sysdate + 6/24), 'YY/MM/DD HH24:MI:SS'), 'yyyy.mm.dd hh24:mi:ss') - to_timestamp(to_char(s.CREATION_TIME, 'yyyy.mm.dd hh24:mi:ss'), 'YY/MM/DD HH24:MI:SS')), 'dd hh24:mi:ss'),8,12)
         when 'B' then substr(to_char((to_timestamp(to_char((Sysdate + 1), 'YY/MM/DD HH24:MI:SS'), 'yyyy.mm.dd hh24:mi:ss') - to_timestamp(to_char(s.CREATION_TIME, 'YY/MM/DD HH24:MI:SS'), 'yyyy.mm.dd hh24:mi:ss')), 'dd hh24:mi:ss'), 8,12)
         when 'C' then substr(to_char((to_timestamp(to_char((Sysdate + 1), 'YY/MM/DD HH24:MI:SS'), 'yyyy.mm.dd hh24:mi:ss') - to_timestamp(to_char(s.CREATION_TIME, 'YY/MM/DD HH24:MI:SS'), 'yyyy.mm.dd hh24:mi:ss')), 'dd hh24:mi:ss'),8,12)
         else          substr(to_char((to_timestamp(to_char((Sysdate + 1), 'YY/MM/DD HH24:MI:SS'), 'yyyy.mm.dd hh24:mi:ss') - to_timestamp(to_char(s.CREATION_TIME, 'YY/MM/DD HH24:MI:SS'), 'yyyy.mm.dd hh24:mi:ss')), 'dd hh24:mi:ss'), 8,12)
        end as TIME_LEFT_OVERRUN,

       c.URSACHE_KURZ as URSACHE_KURZ,
       s.BEARBEITER as BEARBEITER
      from dash_omc_cases c, dash_omc_sap s
      where c.CASE_ID = s.CASE_ID
      order by c.CREATION_TIME desc";

像这样:

select * from (
select ROW_NUMBER() OVER(order by c.CREATION_TIME desc) rn, c.case_id as NGM_ID,   
       s.NE_PRIORITAET as NE_PRIO,
       case substr(s.NE_ID, 2,1)
         when '0' then 'Zentrale'
         when '1' then 'Nord'
         when '2' then 'Nord' 
         when '3' then 'Ost'
         when '4' then 'Ost'
         when '5' then 'Mitte'
         when '6' then 'West'
         when '7' then 'Süd'
         when '8' then 'Mitte'
         when '9' then 'Süd'
         else          'Error'
       end as REGION,         
       c.STATUS_NGM as NGM_STATUS,
       s.AUFTRAG as AUFTRAG,
       s.NE_ID as NE_ID,
       s.STATUS as SAP_STATUS,
       substr(to_timestamp(to_char(Sysdate, 'YY/MM/DD HH24:MI:SS'), 'YY/MM/DD HH24:MI:SS') - to_timestamp(to_char(s.CREATION_TIME, 'YY/MM/DD HH24:MI:SS'), 'YY/MM/DD HH24:MI:SS'), 8,12) as DIFF_BEGINN_SAP_ENDE,
      case trim(s.KATEGORIE)
         when '1' then 'INSLA'
         when '2' then 'OUTSLA'
         else          s.KATEGORIE
       end as SLA,
       to_char(c.CREATION_TIME, 'YY/MM/DD HH24:MI:SS')
        as NGM_CREATION_TIME,
       case s.NE_PRIORITAET
         when 'A' then substr(to_char((to_timestamp(to_char((Sysdate + 6/24), 'YY/MM/DD HH24:MI:SS'), 'yyyy.mm.dd hh24:mi:ss') - to_timestamp(to_char(s.CREATION_TIME, 'yyyy.mm.dd hh24:mi:ss'), 'YY/MM/DD HH24:MI:SS')), 'dd hh24:mi:ss'),8,12)
         when 'B' then substr(to_char((to_timestamp(to_char((Sysdate + 1), 'YY/MM/DD HH24:MI:SS'), 'yyyy.mm.dd hh24:mi:ss') - to_timestamp(to_char(s.CREATION_TIME, 'YY/MM/DD HH24:MI:SS'), 'yyyy.mm.dd hh24:mi:ss')), 'dd hh24:mi:ss'), 8,12)
         when 'C' then substr(to_char((to_timestamp(to_char((Sysdate + 1), 'YY/MM/DD HH24:MI:SS'), 'yyyy.mm.dd hh24:mi:ss') - to_timestamp(to_char(s.CREATION_TIME, 'YY/MM/DD HH24:MI:SS'), 'yyyy.mm.dd hh24:mi:ss')), 'dd hh24:mi:ss'),8,12)
         else          substr(to_char((to_timestamp(to_char((Sysdate + 1), 'YY/MM/DD HH24:MI:SS'), 'yyyy.mm.dd hh24:mi:ss') - to_timestamp(to_char(s.CREATION_TIME, 'YY/MM/DD HH24:MI:SS'), 'yyyy.mm.dd hh24:mi:ss')), 'dd hh24:mi:ss'), 8,12)
        end as TIME_LEFT_OVERRUN,

       c.URSACHE_KURZ as URSACHE_KURZ,
       s.BEARBEITER as BEARBEITER
      from dash_omc_cases c, dash_omc_sap s
      where c.CASE_ID = s.CASE_ID
) where rn between 5 and 30
order by rn

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM