티스토리 뷰
반응형
없는 데이터 강제로 만들기 및 정해진 데이터 표로 리스트 뿌리기
미련하면서도 억지로 만든쿼리
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
반응형
'Database' 카테고리의 다른 글
[ORACLE] 여러 로우 값을 하나의 컬럼으로 바꾸는 방법 (0) | 2014.09.24 |
---|---|
[ORACLE]날짜 함수 및 날짜구하기 (0) | 2014.09.18 |
[ORACLE] 오라클 재구동 (0) | 2014.08.13 |
[MSSQL]MSSQL 2005 유지관리 계획 등록 오류 (0) | 2013.07.10 |
[ORACLE]OUT JOIN (0) | 2013.06.14 |
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- delete
- IP
- 윈도우
- Toad
- java
- apache
- 설정
- tomcat
- 서버
- 백업
- select
- DB
- Oracle
- table
- 자동차
- eclipse
- 데이터
- 리눅스
- Linux
- MySQL
- 파일
- sql
- 오라클
- server
- mssql
- Shell
- user
- Windows
- DATABASE
- 테이블
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함