|
|
|
@ -6,16 +6,24 @@
|
|
|
|
|
/* 마약/항정 and 중점/일반 별 통계 */
|
|
|
|
|
WITH tgt AS (
|
|
|
|
|
SELECT tdm.dept_cd
|
|
|
|
|
, IF(tpi.nrcd_se_nm = '대마', '1', '0') AS 대마
|
|
|
|
|
, IF(tpi.nrcd_se_nm = '마약', '1', '0') AS 마약
|
|
|
|
|
, IF(tpi.nrcd_se_nm = '한외마약', '1', '0') AS 한외마약
|
|
|
|
|
, IF(tpi.nrcd_se_nm = '향정', '1', '0') AS 향정
|
|
|
|
|
, IF(tpi.nrcd_se_nm = '향정제외', '1', '0') AS 향정제외
|
|
|
|
|
, IF(tpi.nrcd_se_nm IS NULL, '1', '0') AS 기타
|
|
|
|
|
, IF(tpi.nrcd_se_nm = '대마', 1, '0') AS 대마
|
|
|
|
|
, IF(tpi.nrcd_se_nm = '마약', 1, '0') AS 마약
|
|
|
|
|
, IF(tpi.nrcd_se_nm = '한외마약', 1, '0') AS 한외마약
|
|
|
|
|
, IF(tpi.nrcd_se_nm = '향정', 1, '0') AS 향정
|
|
|
|
|
, IF(tpi.nrcd_se_nm = '향정제외', 1, '0') AS 향정제외
|
|
|
|
|
, IF(tpi.nrcd_se_nm IS NULL, 1, '0') AS 기타
|
|
|
|
|
, IF(tpi.prtm_se_nm = '비마약류', 1, 0) AS 비마약류
|
|
|
|
|
, IF(tpi.prtm_se_nm = '일반관리대상', 1, 0) AS 일반관리대상
|
|
|
|
|
, IF(tpi.prtm_se_nm = '중점관리대상', 1, 0) AS 중점관리대상
|
|
|
|
|
, COUNT(tpi.prduct_cd) OVER(PARTITION BY tdm.dept_cd) AS TOTAL
|
|
|
|
|
, IF(tpi.nrcd_se_nm = '대마', tdmd.dsuse_qy, '0') AS 대마qy
|
|
|
|
|
, IF(tpi.nrcd_se_nm = '마약', tdmd.dsuse_qy, '0') AS 마약qy
|
|
|
|
|
, IF(tpi.nrcd_se_nm = '한외마약', tdmd.dsuse_qy, '0') AS 한외마약qy
|
|
|
|
|
, IF(tpi.nrcd_se_nm = '향정', tdmd.dsuse_qy, '0') AS 향정qy
|
|
|
|
|
, IF(tpi.nrcd_se_nm = '향정제외', tdmd.dsuse_qy, '0') AS 향정제외qy
|
|
|
|
|
, IF(tpi.nrcd_se_nm IS NULL, tdmd.dsuse_qy, '0') AS 기타qy
|
|
|
|
|
, IF(tpi.prtm_se_nm = '비마약류', tdmd.dsuse_qy, 0) AS 비마약류qy
|
|
|
|
|
, IF(tpi.prtm_se_nm = '일반관리대상', tdmd.dsuse_qy, 0) AS 일반관리대상qy
|
|
|
|
|
, IF(tpi.prtm_se_nm = '중점관리대상', tdmd.dsuse_qy, 0) AS 중점관리대상qy
|
|
|
|
|
FROM tb_dsuse_mgt tdm
|
|
|
|
|
JOIN tb_dsuse_mgt_dtl tdmd ON tdm.dscdmng_id = tdmd.dscdmng_id
|
|
|
|
|
JOIN tb_prduct_info tpi ON tdmd.prduct_cd = tpi.prduct_cd
|
|
|
|
@ -49,6 +57,17 @@
|
|
|
|
|
, SUM(tgt.일반관리대상) AS 일반관리대상
|
|
|
|
|
, SUM(tgt.중점관리대상) AS 중점관리대상
|
|
|
|
|
, SUM(tgt.비마약류 + tgt.일반관리대상 + tgt.중점관리대상) AS 중점일반계
|
|
|
|
|
, SUM(tgt.대마qy) AS 대마qy
|
|
|
|
|
, SUM(tgt.마약qy) AS 마약qy
|
|
|
|
|
, SUM(tgt.한외마약qy) AS 한외마약qy
|
|
|
|
|
, SUM(tgt.향정qy) AS 향정qy
|
|
|
|
|
, SUM(tgt.향정제외qy) AS 향정제외qy
|
|
|
|
|
, SUM(tgt.기타qy) AS 기타qy
|
|
|
|
|
, SUM(tgt.대마qy + tgt.마약qy + tgt.한외마약qy + tgt.향정qy + tgt.향정제외qy + tgt.기타qy) AS 마약향정계qy
|
|
|
|
|
, SUM(tgt.비마약류qy) AS 비마약류qy
|
|
|
|
|
, SUM(tgt.일반관리대상qy) AS 일반관리대상qy
|
|
|
|
|
, SUM(tgt.중점관리대상qy) AS 중점관리대상qy
|
|
|
|
|
, SUM(tgt.비마약류qy + tgt.일반관리대상qy + tgt.중점관리대상qy) AS 중점일반계qy
|
|
|
|
|
FROM tgt
|
|
|
|
|
GROUP BY tgt.dept_cd
|
|
|
|
|
UNION ALL
|
|
|
|
@ -64,6 +83,17 @@
|
|
|
|
|
, SUM(tgt.일반관리대상) AS 일반관리대상
|
|
|
|
|
, SUM(tgt.중점관리대상) AS 중점관리대상
|
|
|
|
|
, SUM(tgt.비마약류 + tgt.일반관리대상 + tgt.중점관리대상) AS 중점일반계
|
|
|
|
|
, SUM(tgt.대마qy) AS 대마qy
|
|
|
|
|
, SUM(tgt.마약qy) AS 마약qy
|
|
|
|
|
, SUM(tgt.한외마약qy) AS 한외마약qy
|
|
|
|
|
, SUM(tgt.향정qy) AS 향정qy
|
|
|
|
|
, SUM(tgt.향정제외qy) AS 향정제외qy
|
|
|
|
|
, SUM(tgt.기타qy) AS 기타qy
|
|
|
|
|
, SUM(tgt.대마qy + tgt.마약qy + tgt.한외마약qy + tgt.향정qy + tgt.향정제외qy + tgt.기타qy) AS 마약향정계qy
|
|
|
|
|
, SUM(tgt.비마약류qy) AS 비마약류qy
|
|
|
|
|
, SUM(tgt.일반관리대상qy) AS 일반관리대상qy
|
|
|
|
|
, SUM(tgt.중점관리대상qy) AS 중점관리대상qy
|
|
|
|
|
, SUM(tgt.비마약류qy + tgt.일반관리대상qy + tgt.중점관리대상qy) AS 중점일반계qy
|
|
|
|
|
FROM tgt
|
|
|
|
|
) T
|
|
|
|
|
LEFT JOIN tb_dept td
|
|
|
|
@ -82,6 +112,10 @@
|
|
|
|
|
, IF(tdm.prgrs_stts_cd = '06', 1, 0) AS rslt
|
|
|
|
|
, IF(tdm.prgrs_stts_cd = '21', 1, 0) AS mapping
|
|
|
|
|
, IF(tdm.prgrs_stts_cd = '99', 1, 0) AS cplt
|
|
|
|
|
, IF(tdm.prgrs_stts_cd = '01', tdmd.dsuse_qy, 0) AS receiptQy
|
|
|
|
|
, IF(tdm.prgrs_stts_cd = '06', tdmd.dsuse_qy, 0) AS rsltQy
|
|
|
|
|
, IF(tdm.prgrs_stts_cd = '21', tdmd.dsuse_qy, 0) AS mappingQy
|
|
|
|
|
, IF(tdm.prgrs_stts_cd = '99', tdmd.dsuse_qy, 0) AS cpltQy
|
|
|
|
|
FROM tb_dsuse_mgt tdm
|
|
|
|
|
JOIN tb_dsuse_mgt_dtl tdmd
|
|
|
|
|
ON tdm.dscdmng_id = tdmd.dscdmng_id
|
|
|
|
@ -102,7 +136,6 @@
|
|
|
|
|
</if>
|
|
|
|
|
)
|
|
|
|
|
SELECT T.*
|
|
|
|
|
-- , ROW_NUMBER() over (order by prduct_nm) AS ROW_NUM
|
|
|
|
|
, ROW_NUMBER() OVER (ORDER BY T.dept_cd, T.prduct_nm, T.prduct_cd) AS ROW_NUM
|
|
|
|
|
, IF(td.dept_nm IS NULL, T.dept_cd, dept_nm) AS dept_nm
|
|
|
|
|
FROM (
|
|
|
|
@ -113,6 +146,10 @@
|
|
|
|
|
, SUM(tgt.rslt) AS rsltCnt
|
|
|
|
|
, SUM(tgt.mapping) AS mappingCnt
|
|
|
|
|
, SUM(tgt.cplt) AS cpltCnt
|
|
|
|
|
, SUM(tgt.receiptQy) AS receiptQy
|
|
|
|
|
, SUM(tgt.rsltQy) AS rsltQy
|
|
|
|
|
, SUM(tgt.mappingQy) AS mappingQy
|
|
|
|
|
, SUM(tgt.cpltQy) AS cpltQy
|
|
|
|
|
, COUNT(tgt.dscdmng_id) AS dsuseCnt
|
|
|
|
|
, SUM(tgt.dsuse_qy) AS dsuseQy
|
|
|
|
|
FROM tgt
|
|
|
|
@ -125,6 +162,10 @@
|
|
|
|
|
, SUM(tgt.rslt) AS rsltCnt
|
|
|
|
|
, SUM(tgt.mapping) AS mappingCnt
|
|
|
|
|
, SUM(tgt.cplt) AS cpltCnt
|
|
|
|
|
, SUM(tgt.receiptQy) AS receiptQy
|
|
|
|
|
, SUM(tgt.rsltQy) AS rsltQy
|
|
|
|
|
, SUM(tgt.mappingQy) AS mappingQy
|
|
|
|
|
, SUM(tgt.cpltQy) AS cpltQy
|
|
|
|
|
, count(tgt.dscdmng_id) AS dsuseCnt
|
|
|
|
|
, sum(tgt.dsuse_qy) AS dsuseQy
|
|
|
|
|
FROM tgt
|
|
|
|
@ -149,6 +190,13 @@
|
|
|
|
|
, IF(tbi.induty_nm = '마약류제조업', 1, 0) AS 마약류제조업
|
|
|
|
|
, IF(tbi.induty_nm = '마약류취급의료업', 1, 0) AS 마약류취급의료업
|
|
|
|
|
, IF(tbi.induty_nm = '마약류취급학술연구', 1, 0) AS 마약류취급학술연구
|
|
|
|
|
, IF(tbi.induty_nm = '마약류도매업', tdmd.dsuse_qy, 0) AS 마약류도매업Qy
|
|
|
|
|
, IF(tbi.induty_nm = '마약류소매업', tdmd.dsuse_qy, 0) AS 마약류소매업Qy
|
|
|
|
|
, IF(tbi.induty_nm = '마약류수출입업', tdmd.dsuse_qy, 0) AS 마약류수출입업Qy
|
|
|
|
|
, IF(tbi.induty_nm = '마약류원료사용', tdmd.dsuse_qy, 0) AS 마약류원료사용Qy
|
|
|
|
|
, IF(tbi.induty_nm = '마약류제조업', tdmd.dsuse_qy, 0) AS 마약류제조업Qy
|
|
|
|
|
, IF(tbi.induty_nm = '마약류취급의료업', tdmd.dsuse_qy, 0) AS 마약류취급의료업Qy
|
|
|
|
|
, IF(tbi.induty_nm = '마약류취급학술연구', tdmd.dsuse_qy, 0) AS 마약류취급학술연구Qy
|
|
|
|
|
FROM tb_dsuse_mgt tdm
|
|
|
|
|
JOIN tb_dsuse_mgt_dtl tdmd
|
|
|
|
|
ON tdm.dscdmng_id = tdmd.dscdmng_id
|
|
|
|
@ -180,7 +228,13 @@
|
|
|
|
|
, SUM(tgt.마약류제조업) AS 마약류제조업
|
|
|
|
|
, SUM(tgt.마약류취급의료업) AS 마약류취급의료업
|
|
|
|
|
, SUM(tgt.마약류취급학술연구) AS 마약류취급학술연구
|
|
|
|
|
-- , SUM(tgt.마약류도매업 + tgt.마약류소매업 + tgt.마약류수출입업 + tgt.마약류원료사용 + tgt.마약류제조업 + tgt.마약류취급의료업 + tgt.마약류취급학술연구) AS 계
|
|
|
|
|
, SUM(tgt.마약류도매업Qy) AS 마약류도매업Qy
|
|
|
|
|
, SUM(tgt.마약류소매업Qy) AS 마약류소매업Qy
|
|
|
|
|
, SUM(tgt.마약류수출입업Qy) AS 마약류수출입업Qy
|
|
|
|
|
, SUM(tgt.마약류원료사용Qy) AS 마약류원료사용Qy
|
|
|
|
|
, SUM(tgt.마약류제조업Qy) AS 마약류제조업Qy
|
|
|
|
|
, SUM(tgt.마약류취급의료업Qy) AS 마약류취급의료업Qy
|
|
|
|
|
, SUM(tgt.마약류취급학술연구Qy) AS 마약류취급학술연구Qy
|
|
|
|
|
, COUNT(tgt.dscdmng_id) as dsuseCnt
|
|
|
|
|
, SUM(tgt.dsuse_qy) as dsuseQy
|
|
|
|
|
FROM tgt
|
|
|
|
@ -194,7 +248,13 @@
|
|
|
|
|
, SUM(tgt.마약류제조업) AS 마약류제조업
|
|
|
|
|
, SUM(tgt.마약류취급의료업) AS 마약류취급의료업
|
|
|
|
|
, SUM(tgt.마약류취급학술연구) AS 마약류취급학술연구
|
|
|
|
|
-- , SUM(tgt.마약류도매업 + tgt.마약류소매업 + tgt.마약류수출입업 + tgt.마약류원료사용 + tgt.마약류제조업 + tgt.마약류취급의료업 + tgt.마약류취급학술연구) AS 계
|
|
|
|
|
, SUM(tgt.마약류도매업Qy) AS 마약류도매업Qy
|
|
|
|
|
, SUM(tgt.마약류소매업Qy) AS 마약류소매업Qy
|
|
|
|
|
, SUM(tgt.마약류수출입업Qy) AS 마약류수출입업Qy
|
|
|
|
|
, SUM(tgt.마약류원료사용Qy) AS 마약류원료사용Qy
|
|
|
|
|
, SUM(tgt.마약류제조업Qy) AS 마약류제조업Qy
|
|
|
|
|
, SUM(tgt.마약류취급의료업Qy) AS 마약류취급의료업Qy
|
|
|
|
|
, SUM(tgt.마약류취급학술연구Qy) AS 마약류취급학술연구Qy
|
|
|
|
|
, COUNT(tgt.dscdmng_id) AS dsuseCnt
|
|
|
|
|
, SUM(tgt.dsuse_qy) AS dsuseQy
|
|
|
|
|
FROM tgt
|
|
|
|
@ -217,6 +277,10 @@
|
|
|
|
|
, IF(tdm.prgrs_stts_cd = '06', 1, 0) AS rslt
|
|
|
|
|
, IF(tdm.prgrs_stts_cd = '21', 1, 0) AS mapping
|
|
|
|
|
, IF(tdm.prgrs_stts_cd = '99', 1, 0) AS cplt
|
|
|
|
|
, IF(tdm.prgrs_stts_cd = '01', tdmd.dsuse_qy, 0) AS receiptQy
|
|
|
|
|
, IF(tdm.prgrs_stts_cd = '06', tdmd.dsuse_qy, 0) AS rsltQy
|
|
|
|
|
, IF(tdm.prgrs_stts_cd = '21', tdmd.dsuse_qy, 0) AS mappingQy
|
|
|
|
|
, IF(tdm.prgrs_stts_cd = '99', tdmd.dsuse_qy, 0) AS cpltQy
|
|
|
|
|
FROM tb_dsuse_mgt tdm
|
|
|
|
|
JOIN tb_dsuse_mgt_dtl tdmd
|
|
|
|
|
ON tdm.dscdmng_id = tdmd.dscdmng_id
|
|
|
|
@ -248,6 +312,10 @@
|
|
|
|
|
, SUM(tgt.rslt) AS rsltCnt
|
|
|
|
|
, SUM(tgt.mapping) AS mappingCnt
|
|
|
|
|
, SUM(tgt.cplt) AS cpltCnt
|
|
|
|
|
, SUM(tgt.receiptQy) AS receiptQy
|
|
|
|
|
, SUM(tgt.rsltQy) AS rsltQy
|
|
|
|
|
, SUM(tgt.mappingQy) AS mappingQy
|
|
|
|
|
, SUM(tgt.cpltQy) AS cpltQy
|
|
|
|
|
, COUNT(tgt.dscdmng_id) AS dsuseCnt
|
|
|
|
|
, SUM(tgt.dsuse_qy) AS dsuseQy
|
|
|
|
|
FROM tgt
|
|
|
|
@ -261,6 +329,10 @@
|
|
|
|
|
, SUM(tgt.rslt) AS rsltCnt
|
|
|
|
|
, SUM(tgt.mapping) AS mappingCnt
|
|
|
|
|
, SUM(tgt.cplt) AS cpltCnt
|
|
|
|
|
, SUM(tgt.receiptQy) AS receiptQy
|
|
|
|
|
, SUM(tgt.rsltQy) AS rsltQy
|
|
|
|
|
, SUM(tgt.mappingQy) AS mappingQy
|
|
|
|
|
, SUM(tgt.cpltQy) AS cpltQy
|
|
|
|
|
, count(tgt.dscdmng_id) AS dsuseCnt
|
|
|
|
|
, sum(tgt.dsuse_qy) AS dsuseQy
|
|
|
|
|
FROM tgt
|
|
|
|
|