簡體   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