티스토리 뷰

반응형

없는 데이터 강제로 만들기 및 정해진 데이터 표로 리스트 뿌리기

미련하면서도 억지로 만든쿼리

 

SELECT * FROM
(
SELECT SUBSTR(MARKETING_DATE,0,7) AS DAYS, G_CATE, COUNT(G_CATE) AS CNT 
FROM TB_MARKETING   
WHERE SUBSTR(MARKETING_DATE,0,4) = SUBSTR(TO_CHAR(SYSDATE,'YYYYMMDD'),0,4) 
AND G_CATE IN  ('공제회','국가기관','생손보사','은행(중앙회)','금융기관','기타')  
GROUP BY SUBSTR(MARKETING_DATE,0,7),G_CATE
UNION ALL
SELECT DAYS,G_CATE,CNT FROM APLUS_V_TB_MARKETING_ANNUAL
)
ORDER BY DAYS DESC, DECODE(G_CATE,'국가기관',1,'공제회',2,'생손보사',3,'은행(중앙회)',4,'금융기관',5,'기타',6)

 

-----------------------------------------------

APLUS_V_TB_MARKETING_ANNUAL DDL

 

 

CREATE OR REPLACE FORCE VIEW APLUSORA.APLUS_V_TB_MARKETING_ANNUAL
(
   DAYS,
   G_CATE,
   CNT
)
AS
SELECT TO_CHAR(SYSDATE,'YYYY-MM') AS DAYS, '공제회' AS G_CATE, 0 AS CNT FROM DUAL
WHERE 0 =
(
    SELECT COUNT(1) AS CNT FROM TB_MARKETING WHERE SUBSTR(MARKETING_DATE,0,7) = TO_CHAR(SYSDATE,'YYYY-MM') AND G_CATE = '공제회'
)
UNION ALL
SELECT TO_CHAR(SYSDATE,'YYYY-MM') AS DAYS, '국가기관' AS G_CATE, 0 AS CNT FROM DUAL
WHERE 0 =
(
    SELECT COUNT(1) AS CNT FROM TB_MARKETING WHERE SUBSTR(MARKETING_DATE,0,7) = TO_CHAR(SYSDATE,'YYYY-MM') AND G_CATE = '국가기관'
)
UNION ALL
SELECT TO_CHAR(SYSDATE,'YYYY-MM') AS DAYS, '생손보사' AS G_CATE, 0 AS CNT FROM DUAL
WHERE 0 =
(
    SELECT COUNT(1) AS CNT FROM TB_MARKETING WHERE SUBSTR(MARKETING_DATE,0,7) = TO_CHAR(SYSDATE,'YYYY-MM') AND G_CATE = '생손보사'
)
UNION ALL
SELECT TO_CHAR(SYSDATE,'YYYY-MM') AS DAYS, '은행(중앙회)' AS G_CATE, 0 AS CNT FROM DUAL
WHERE 0 =
(
    SELECT COUNT(1) AS CNT FROM TB_MARKETING WHERE SUBSTR(MARKETING_DATE,0,7) = TO_CHAR(SYSDATE,'YYYY-MM') AND G_CATE = '은행(중앙회)'
)
UNION ALL
SELECT TO_CHAR(SYSDATE,'YYYY-MM') AS DAYS, '금융기관' AS G_CATE, 0 AS CNT FROM DUAL
WHERE 0 =
(
    SELECT COUNT(1) AS CNT FROM TB_MARKETING WHERE SUBSTR(MARKETING_DATE,0,7) = TO_CHAR(SYSDATE,'YYYY-MM') AND G_CATE = '금융기관'
)
UNION ALL
SELECT TO_CHAR(SYSDATE,'YYYY-MM') AS DAYS, '기타' AS G_CATE, 0 AS CNT FROM DUAL
WHERE 0 =
(
    SELECT COUNT(1) AS CNT FROM TB_MARKETING WHERE SUBSTR(MARKETING_DATE,0,7) = TO_CHAR(SYSDATE,'YYYY-MM') AND G_CATE = '기타'
)
UNION ALL
SELECT TO_CHAR(ADD_MONTHS(SYSDATE,-1),'YYYY-MM') AS DAYS, '공제회' AS G_CATE, 0 AS CNT FROM DUAL
WHERE 0 =
(
    SELECT COUNT(1) AS CNT FROM TB_MARKETING WHERE SUBSTR(MARKETING_DATE,0,7) = TO_CHAR(ADD_MONTHS(SYSDATE,-1),'YYYY-MM') AND G_CATE = '공제회'
)
UNION ALL
SELECT TO_CHAR(ADD_MONTHS(SYSDATE,-1),'YYYY-MM') AS DAYS, '국가기관' AS G_CATE, 0 AS CNT FROM DUAL
WHERE 0 =
(
    SELECT COUNT(1) AS CNT FROM TB_MARKETING WHERE SUBSTR(MARKETING_DATE,0,7) = TO_CHAR(ADD_MONTHS(SYSDATE,-1),'YYYY-MM') AND G_CATE = '국가기관'
)
UNION ALL
SELECT TO_CHAR(ADD_MONTHS(SYSDATE,-1),'YYYY-MM') AS DAYS, '생손보사' AS G_CATE, 0 AS CNT FROM DUAL
WHERE 0 =
(
    SELECT COUNT(1) AS CNT FROM TB_MARKETING WHERE SUBSTR(MARKETING_DATE,0,7) = TO_CHAR(ADD_MONTHS(SYSDATE,-1),'YYYY-MM') AND G_CATE = '생손보사'
)
UNION ALL
SELECT TO_CHAR(ADD_MONTHS(SYSDATE,-1),'YYYY-MM') AS DAYS, '은행(중앙회)' AS G_CATE, 0 AS CNT FROM DUAL
WHERE 0 =
(
    SELECT COUNT(1) AS CNT FROM TB_MARKETING WHERE SUBSTR(MARKETING_DATE,0,7) = TO_CHAR(ADD_MONTHS(SYSDATE,-1),'YYYY-MM') AND G_CATE = '은행(중앙회)'
)
UNION ALL
SELECT TO_CHAR(ADD_MONTHS(SYSDATE,-1),'YYYY-MM') AS DAYS, '금융기관' AS G_CATE, 0 AS CNT FROM DUAL
WHERE 0 =
(
    SELECT COUNT(1) AS CNT FROM TB_MARKETING WHERE SUBSTR(MARKETING_DATE,0,7) = TO_CHAR(ADD_MONTHS(SYSDATE,-1),'YYYY-MM') AND G_CATE = '금융기관'
)
UNION ALL
SELECT TO_CHAR(ADD_MONTHS(SYSDATE,-1),'YYYY-MM') AS DAYS, '기타' AS G_CATE, 0 AS CNT FROM DUAL
WHERE 0 =
(
    SELECT COUNT(1) AS CNT FROM TB_MARKETING WHERE SUBSTR(MARKETING_DATE,0,7) = TO_CHAR(ADD_MONTHS(SYSDATE,-1),'YYYY-MM') AND G_CATE = '기타'
)

 

 

APLUS_V_TB_MARKETING_ANNUAL.SQL

 

 

반응형
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
글 보관함