ORACLE SQL: создание представления, которое извлекает данные только с определенной даты - PullRequest
0 голосов
/ 08 февраля 2019

Я хочу изменить свое представление на получение только данных с определенной даты, например, 1 месяц назад, и забыть все старые данные.

     SELECT trunc(TIME) TIME,SIDSTE_AGENT,TEAM_CODE,CDN,TLFNR,
            OPTAGELSE,MAX(DECODE(QUESTION_ID, 201, KARAKTER)) AS SP1
       FROM KS_DRIFT.KT_BESVARELSE besv
 INNER JOIN KS_DRIFT.KT_KARAKTER kara 
         ON besv.EKSTERN_ID = kara.BESVARELSE_ID 
        AND besv.TYPE = kara.TYPE
  LEFT JOIN KS_DRIFT.V_AGENT_ALLOCATION 
         ON FØRSTE_AGENT = AGENT_INITIALS 
        AND TIME BETWEEN ALLOCATION_START 
        AND NVL(ALLOCATION_END, SYSDATE)
      WHERE CDN NOT IN ( 5400, 7635, 8882,8200,8210,8702) AND besv.TYPE = 0
   GROUP BY TIME, SIDSTE_AGENT, TEAM_CODE, CDN, TLFNR, OPTAGELSE
   ORDER BY TIME desc

Ответы [ 2 ]

0 голосов
/ 08 февраля 2019

Вот, пожалуйста,

SELECT 
     trunc(TIME) TIME,
     SIDSTE_AGENT,
     TEAM_CODE,
     CDN,
     TLFNR,
     OPTAGELSE,
     MAX(DECODE(QUESTION_ID, 201, KARAKTER)) AS SP1
    FROM KS_DRIFT.KT_BESVARELSE besv
     INNER JOIN KS_DRIFT.KT_KARAKTER kara ON besv.EKSTERN_ID = kara.BESVARELSE_ID AND besv.TYPE = kara.TYPE
     LEFT JOIN KS_DRIFT.V_AGENT_ALLOCATION ON FØRSTE_AGENT = AGENT_INITIALS AND TIME BETWEEN ALLOCATION_START AND NVL(ALLOCATION_END, SYSDATE)
    WHERE CDN NOT IN ( 5400, 7635, 8882,8200,8210,8702) AND besv.TYPE = 0
    AND trunc(TIME) >= ADD_MONTHS(trunc(sysdate),-1)
    GROUP BY TIME, SIDSTE_AGENT, TEAM_CODE, CDN, TLFNR, OPTAGELSE
    ORDER BY TIME desc
0 голосов
/ 08 февраля 2019

Это может работать:

SELECT 
 trunc(TIME) TIME,
 SIDSTE_AGENT,
 TEAM_CODE,
 CDN,
 TLFNR,
 OPTAGELSE,
 MAX(DECODE(QUESTION_ID, 201, KARAKTER)) AS SP1
FROM KS_DRIFT.KT_BESVARELSE besv
 INNER JOIN KS_DRIFT.KT_KARAKTER kara ON besv.EKSTERN_ID = kara.BESVARELSE_ID AND besv.TYPE = kara.TYPE
 LEFT JOIN KS_DRIFT.V_AGENT_ALLOCATION ON FØRSTE_AGENT = AGENT_INITIALS AND TIME BETWEEN ALLOCATION_START AND NVL(ALLOCATION_END, SYSDATE)
WHERE CDN NOT IN ( 5400, 7635, 8882,8200,8210,8702) AND besv.TYPE = 0

AND time > SYSDATE - interval '1' month

GROUP BY TIME, SIDSTE_AGENT, TEAM_CODE, CDN, TLFNR, OPTAGELSE
ORDER BY TIME desc
...