|
|
|
@ -108,10 +108,13 @@ where use_yn = 'Y';
|
|
|
|
|
, tdm.DSUSE_MTH_CD
|
|
|
|
|
, tcc.CODE_VAL AS DSUSE_MTH_NM
|
|
|
|
|
, tdm.DSUSE_DE
|
|
|
|
|
-- , tf.FILE_ID
|
|
|
|
|
-- , tf.FILE_NM
|
|
|
|
|
-- , IF(tf.FILE_ID IS NULL, 'Y', 'N') AS ins_yn
|
|
|
|
|
-- , IFNULL(tf.FILE_ID, 'N') AS ins_yn
|
|
|
|
|
, IF('' = tdm.DSCDMNG_ID, 'Y', 'N') AS SEL_YN
|
|
|
|
|
, (SELECT count(dscdmng_id)
|
|
|
|
|
FROM tb_dsuse_mgt
|
|
|
|
|
WHERE use_yn = 'Y'
|
|
|
|
|
AND dept_cd = '4050149'
|
|
|
|
|
AND dsuse_mth_cd = '1'
|
|
|
|
|
AND dsuse_de = '20240709') AS CNT
|
|
|
|
|
FROM tb_dsuse_mgt tdm
|
|
|
|
|
JOIN tb_cmn_code tcc
|
|
|
|
|
ON (tdm.dsuse_mth_cd = tcc.code
|
|
|
|
@ -125,7 +128,361 @@ where use_yn = 'Y';
|
|
|
|
|
)
|
|
|
|
|
AND tdm.use_yn = 'Y'
|
|
|
|
|
AND tdm.dept_cd = '4050149'
|
|
|
|
|
AND tdm.dsuse_mth_cd = '3'
|
|
|
|
|
AND tdm.dsuse_mth_cd = '1'
|
|
|
|
|
AND tdm.dsuse_de = '20240709'
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
SELECT
|
|
|
|
|
A.DSCDMNG_ID /* 폐기관리 ID */
|
|
|
|
|
, A.DEPT_CD /* 부서 코드 */
|
|
|
|
|
, td.DEPT_NM /* 부서명 */
|
|
|
|
|
, A.USER_ID /* 사용자 ID */
|
|
|
|
|
, A.PRGRS_STTS_CD /* 진행상태 코드 */
|
|
|
|
|
, GET_CODE_NM("ADDS11", A.PRGRS_STTS_CD) PRGRS_STTS_NM /* 진행상태 */
|
|
|
|
|
, A.BSSH_CD /* 마약류취급자 식별번호 */
|
|
|
|
|
, A.RND_DTL_RPT_CNT /* 수불_상세_보고_수 */
|
|
|
|
|
, A.HDR_DE /* 취급 일자 */
|
|
|
|
|
, A.DSUSE_SE_CD /* 폐기 구분 코드 */
|
|
|
|
|
, GET_CODE_NM("ADDS03", A.DSUSE_SE_CD) DSUSE_SE_NM /* 폐기 구분 */
|
|
|
|
|
, A.DSUSE_PRV_CD /* 폐기 사유 코드 */
|
|
|
|
|
, GET_CODE_NM("ADDS04", A.DSUSE_PRV_CD) DSUSE_PRV_NM /* 폐기 사유 */
|
|
|
|
|
, A.DSUSE_MTH_CD /* 폐기 방법 코드 */
|
|
|
|
|
, GET_CODE_NM("ADDS05", A.DSUSE_MTH_CD) DSUSE_MTH_NM /* 폐기 방법 */
|
|
|
|
|
, A.DSUSE_LOC /* 폐기 장소 */
|
|
|
|
|
, A.DSUSE_DE /* 폐기 일자 */
|
|
|
|
|
, A.DSUSE_ACDT_DE /* 사고발생일 */
|
|
|
|
|
, A.DSUSE_RMK /* 폐기 비고 */
|
|
|
|
|
, A.STTS /* 처리상태 */
|
|
|
|
|
, A.USR_RPT_ID_NO /* 사용자 보고 식별 번호 */
|
|
|
|
|
, A.ORG_USR_RPT_ID_NO /* 원 사용자 보고 식별 번호 */
|
|
|
|
|
, A.RPT_TY_CD /* 보고 유형 코드 */
|
|
|
|
|
, GET_CODE_NM("ADDS02", A.RPT_TY_CD) RPT_TY_NM /* 보고 유형 */
|
|
|
|
|
, A.USE_YN /* 사용여부 */
|
|
|
|
|
, CASE WHEN A.MDFCN_DT IS NOT NULL THEN A.MDFCN_DT
|
|
|
|
|
ELSE A.REG_DT
|
|
|
|
|
END AS MDFCN_DT /* 수정일시 */
|
|
|
|
|
, CASE WHEN A.MDFR IS NOT NULL THEN A.MDFR
|
|
|
|
|
ELSE A.RGTR
|
|
|
|
|
END AS MDFR /* 수정자 */
|
|
|
|
|
, B.BSSH_NM /* 업체 명 */
|
|
|
|
|
, B.INDUTY_NM /* 업종 명 */
|
|
|
|
|
, B.BIZRNO /* 사업자등록번호 */
|
|
|
|
|
, B.RPRSNTV_NM /* 대표자 명 */
|
|
|
|
|
, B.HPTL_NO /* 요양기관 번호 */
|
|
|
|
|
, B.PRMISN_NO /* 허가번호 */
|
|
|
|
|
FROM TB_DSUSE_MGT A
|
|
|
|
|
JOIN tb_dept td ON A.dept_cd = td.dept_cd
|
|
|
|
|
LEFT JOIN TB_BSSH_INFO B ON A.BSSH_CD = B.BSSH_CD
|
|
|
|
|
WHERE A.USE_YN = 'Y'
|
|
|
|
|
AND A.dept_cd = '4050149'
|
|
|
|
|
AND A.dsuse_de = '20240710'
|
|
|
|
|
order by A.dsuse_de desc, A.dscdmng_id;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** 마약류 구분별 현황 */
|
|
|
|
|
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.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
|
|
|
|
|
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
|
|
|
|
|
)
|
|
|
|
|
SELECT T.*
|
|
|
|
|
, ROW_NUMBER() over (ORDER BY T.dept_cd) AS ROW_NUM
|
|
|
|
|
, IF(td.dept_nm IS NULL, T.dept_cd, dept_nm) AS dept_nm
|
|
|
|
|
FROM (SELECT tgt.dept_cd
|
|
|
|
|
, SUM(tgt.대마) AS '대마'
|
|
|
|
|
, SUM(tgt.마약) AS '마약'
|
|
|
|
|
, SUM(tgt.한외마약) AS '한외마약'
|
|
|
|
|
, SUM(tgt.향정) AS '향정'
|
|
|
|
|
, SUM(tgt.향정제외) AS '향정제외'
|
|
|
|
|
, SUM(tgt.기타) AS '기타'
|
|
|
|
|
, SUM(tgt.대마 + tgt.마약 + tgt.한외마약 + tgt.향정 + tgt.향정제외 + tgt.기타) AS '마약향정계'
|
|
|
|
|
, SUM(tgt.비마약류) AS '비마약류'
|
|
|
|
|
, SUM(tgt.일반관리대상) AS '일반관리대상'
|
|
|
|
|
, SUM(tgt.중점관리대상) AS '중점관리대상'
|
|
|
|
|
, SUM(tgt.비마약류 + tgt.일반관리대상 + tgt.중점관리대상) AS '중점일반계'
|
|
|
|
|
FROM tgt
|
|
|
|
|
GROUP BY tgt.dept_cd
|
|
|
|
|
UNION ALL
|
|
|
|
|
SELECT 'TOTAL' AS dept_cd
|
|
|
|
|
, SUM(tgt.대마) AS '대마'
|
|
|
|
|
, SUM(tgt.마약) AS '마약'
|
|
|
|
|
, SUM(tgt.한외마약) AS '한외마약'
|
|
|
|
|
, SUM(tgt.향정) AS '향정'
|
|
|
|
|
, SUM(tgt.향정제외) AS '향정제외'
|
|
|
|
|
, SUM(tgt.기타) AS '기타'
|
|
|
|
|
, SUM(tgt.대마 + tgt.마약 + tgt.한외마약 + tgt.향정 + tgt.향정제외 + tgt.기타) AS '마약향정계'
|
|
|
|
|
, SUM(tgt.비마약류) AS '비마약류'
|
|
|
|
|
, SUM(tgt.일반관리대상) AS '일반관리대상'
|
|
|
|
|
, SUM(tgt.중점관리대상) AS '중점관리대상'
|
|
|
|
|
, SUM(tgt.비마약류 + tgt.일반관리대상 + tgt.중점관리대상) AS '중점일반계'
|
|
|
|
|
FROM tgt
|
|
|
|
|
) T
|
|
|
|
|
LEFT JOIN tb_dept td
|
|
|
|
|
ON T.dept_cd = td.dept_cd;
|
|
|
|
|
|
|
|
|
|
/** 마약류 제품별 폐기 현황 */
|
|
|
|
|
WITH tgt AS (
|
|
|
|
|
SELECT tpi.prduct_cd
|
|
|
|
|
, tpi.prduct_nm
|
|
|
|
|
, tdm.dscdmng_id
|
|
|
|
|
, tdm.dept_cd
|
|
|
|
|
, tdmd.dsuse_qy
|
|
|
|
|
, IF(tdm.prgrs_stts_cd = '01', 1, 0) AS receipt
|
|
|
|
|
, 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
|
|
|
|
|
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
|
|
|
|
|
)
|
|
|
|
|
SELECT T.*
|
|
|
|
|
-- , ROW_NUMBER() over (order by prduct_nm) AS ROW_NUM
|
|
|
|
|
, ROW_NUMBER() OVER (ORDER BY T.dept_cd, T.prduct_nm) AS ROW_NUM
|
|
|
|
|
, IF(td.dept_nm IS NULL, T.dept_cd, dept_nm) AS dept_nm
|
|
|
|
|
FROM (
|
|
|
|
|
SELECT tgt.dept_cd
|
|
|
|
|
, tgt.prduct_cd AS prduct_cd
|
|
|
|
|
, tgt.prduct_nm AS prduct_nm
|
|
|
|
|
, count(tgt.dscdmng_id) as dsuseCnt
|
|
|
|
|
, sum(tgt.receipt) as receiptCnt
|
|
|
|
|
, sum(tgt.rslt) as rsltCnt
|
|
|
|
|
, sum(tgt.mapping) as mapping
|
|
|
|
|
, sum(tgt.cplt) as cplt
|
|
|
|
|
, sum(tgt.dsuse_qy) as dsuseQy
|
|
|
|
|
FROM tgt
|
|
|
|
|
GROUP BY tgt.dept_cd, tgt.prduct_nm, tgt.prduct_cd
|
|
|
|
|
UNION ALL
|
|
|
|
|
SELECT 'TOTAL' AS dept_cd
|
|
|
|
|
, '' AS prduct_cd
|
|
|
|
|
, '' as prduct_nm
|
|
|
|
|
, count(tgt.dscdmng_id) as dsuseCnt
|
|
|
|
|
, sum(tgt.receipt) as receiptCnt
|
|
|
|
|
, sum(tgt.rslt) as rsltCnt
|
|
|
|
|
, sum(tgt.mapping) as mapping
|
|
|
|
|
, sum(tgt.cplt) as cplt
|
|
|
|
|
, sum(tgt.dsuse_qy) as dsuseQy
|
|
|
|
|
FROM tgt
|
|
|
|
|
) T
|
|
|
|
|
LEFT JOIN tb_dept td
|
|
|
|
|
ON T.dept_cd = td.dept_cd
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WITH tgt AS (
|
|
|
|
|
SELECT tpi.prduct_cd
|
|
|
|
|
, tpi.prduct_nm
|
|
|
|
|
, tdm.dscdmng_id
|
|
|
|
|
, tdm.dept_cd
|
|
|
|
|
, tdmd.dsuse_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
|
|
|
|
|
)
|
|
|
|
|
SELECT tgt.dept_cd
|
|
|
|
|
, tgt.prduct_cd AS prduct_cd
|
|
|
|
|
, tgt.prduct_nm AS prduct_nm
|
|
|
|
|
, count(tgt.dscdmng_id) as dsuseCnt
|
|
|
|
|
, sum(tgt.dsuse_qy) as dsuseQy
|
|
|
|
|
FROM tgt
|
|
|
|
|
GROUP BY tgt.prduct_nm, tgt.prduct_cd
|
|
|
|
|
UNION ALL
|
|
|
|
|
SELECT '' AS dept_cd
|
|
|
|
|
, '' AS prduct_cd
|
|
|
|
|
, ' TOTAL' as prduct_nm
|
|
|
|
|
, count(tgt.dscdmng_id) as dsuseCnt
|
|
|
|
|
, sum(tgt.dsuse_qy) as dsuseQy
|
|
|
|
|
FROM tgt
|
|
|
|
|
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
select tdm.bssh_cd, tbi.bssh_nm, tbi.hdnt_cd, tbi.hdnt_nm, tbi.induty_nm
|
|
|
|
|
from tb_dsuse_mgt tdm
|
|
|
|
|
join tb_bssh_info tbi
|
|
|
|
|
on tdm.bssh_cd = tbi.bssh_cd;
|
|
|
|
|
|
|
|
|
|
select tbi.hdnt_cd, tcc.code_val, count(tbi.hdnt_cd)
|
|
|
|
|
from tb_dsuse_mgt tdm
|
|
|
|
|
join tb_bssh_info tbi
|
|
|
|
|
on tdm.bssh_cd = tbi.bssh_cd
|
|
|
|
|
join tb_cmn_code tcc
|
|
|
|
|
on (tcc.grp_id = 'ADDS13'
|
|
|
|
|
AND tbi.hdnt_cd = tcc.code)
|
|
|
|
|
group by hdnt_cd;
|
|
|
|
|
|
|
|
|
|
select tdm.dept_cd, tbi.induty_nm, count(tbi.induty_nm)
|
|
|
|
|
from tb_dsuse_mgt tdm
|
|
|
|
|
join tb_bssh_info tbi
|
|
|
|
|
on tdm.bssh_cd = tbi.bssh_cd
|
|
|
|
|
group by tdm.dept_cd, tbi.induty_nm;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
select tpi.nrcd_se_nm, count(tpi.prduct_cd)
|
|
|
|
|
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
|
|
|
|
|
group by tpi.nrcd_se_nm;
|
|
|
|
|
|
|
|
|
|
select tpi.prtm_se_nm, count(tpi.prduct_cd)
|
|
|
|
|
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
|
|
|
|
|
group by tpi.prtm_se_nm;
|
|
|
|
|
|
|
|
|
|
select tpi.prduct_cd, tpi.prduct_nm, count(tdm.dscdmng_id) as dsuseCnt, sum(tdmd.dsuse_qy) as dsuseQy
|
|
|
|
|
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
|
|
|
|
|
group by tpi.prduct_cd, tpi.prduct_nm;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
select hdnt_cd, hdnt_nm, count(hdnt_cd)
|
|
|
|
|
from tb_bssh_info
|
|
|
|
|
group by hdnt_cd, hdnt_nm;
|
|
|
|
|
|
|
|
|
|
select induty_nm, count(induty_nm)
|
|
|
|
|
from tb_bssh_info
|
|
|
|
|
group by induty_nm;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WITH tgt AS (
|
|
|
|
|
SELECT tdm.bssh_cd
|
|
|
|
|
, tbi.bssh_nm
|
|
|
|
|
, tbi.induty_nm
|
|
|
|
|
, tdm.dscdmng_id
|
|
|
|
|
, tdm.dept_cd
|
|
|
|
|
, tdmd.dsuse_qy
|
|
|
|
|
, 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 = '마약류원료사용', 1, 0) AS 마약류원료사용
|
|
|
|
|
, IF(tbi.induty_nm = '마약류제조업', 1, 0) AS 마약류제조업
|
|
|
|
|
, IF(tbi.induty_nm = '마약류취급의료업', 1, 0) AS 마약류취급의료업
|
|
|
|
|
, IF(tbi.induty_nm = '마약류취급학술연구', 1, 0) AS 마약류취급학술연구
|
|
|
|
|
FROM tb_dsuse_mgt tdm
|
|
|
|
|
JOIN tb_dsuse_mgt_dtl tdmd
|
|
|
|
|
ON tdm.dscdmng_id = tdmd.dscdmng_id
|
|
|
|
|
JOIN tb_bssh_info tbi
|
|
|
|
|
ON tdm.bssh_cd = tbi.bssh_cd
|
|
|
|
|
)
|
|
|
|
|
SELECT T.*
|
|
|
|
|
, ROW_NUMBER() over (ORDER BY T.dept_cd) AS ROW_NUM
|
|
|
|
|
, IF(td.dept_nm IS NULL, T.dept_cd, dept_nm) AS dept_nm
|
|
|
|
|
FROM (SELECT tgt.dept_cd
|
|
|
|
|
, SUM(tgt.마약류도매업) AS 마약류도매업
|
|
|
|
|
, SUM(tgt.마약류소매업) AS 마약류소매업
|
|
|
|
|
, SUM(tgt.마약류수출입업) AS 마약류수출입업
|
|
|
|
|
, SUM(tgt.마약류원료사용) AS 마약류원료사용
|
|
|
|
|
, SUM(tgt.마약류제조업) AS 마약류제조업
|
|
|
|
|
, SUM(tgt.마약류취급의료업) AS 마약류취급의료업
|
|
|
|
|
, SUM(tgt.마약류취급학술연구) AS 마약류취급학술연구
|
|
|
|
|
, SUM(tgt.마약류도매업 + tgt.마약류소매업 + tgt.마약류수출입업 + tgt.마약류원료사용 + tgt.마약류제조업 + tgt.마약류취급의료업 + tgt.마약류취급학술연구) AS 계
|
|
|
|
|
, COUNT(tgt.dscdmng_id) as dsuseCnt
|
|
|
|
|
, SUM(tgt.dsuse_qy) as dsuseQy
|
|
|
|
|
FROM tgt
|
|
|
|
|
GROUP BY tgt.dept_cd
|
|
|
|
|
UNION ALL
|
|
|
|
|
SELECT 'TOTAL' AS dept_cd
|
|
|
|
|
, SUM(tgt.마약류도매업) AS 마약류도매업
|
|
|
|
|
, SUM(tgt.마약류소매업) AS 마약류소매업
|
|
|
|
|
, SUM(tgt.마약류수출입업) AS 마약류수출입업
|
|
|
|
|
, SUM(tgt.마약류원료사용) AS 마약류원료사용
|
|
|
|
|
, SUM(tgt.마약류제조업) AS 마약류제조업
|
|
|
|
|
, SUM(tgt.마약류취급의료업) AS 마약류취급의료업
|
|
|
|
|
, SUM(tgt.마약류취급학술연구) AS 마약류취급학술연구
|
|
|
|
|
, SUM(tgt.마약류도매업 + tgt.마약류소매업 + tgt.마약류수출입업 + tgt.마약류원료사용 + tgt.마약류제조업 + tgt.마약류취급의료업 + tgt.마약류취급학술연구) AS 계
|
|
|
|
|
, COUNT(tgt.dscdmng_id) as dsuseCnt
|
|
|
|
|
, SUM(tgt.dsuse_qy) as dsuseQy
|
|
|
|
|
FROM tgt
|
|
|
|
|
) T
|
|
|
|
|
LEFT JOIN tb_dept td
|
|
|
|
|
ON T.dept_cd = td.dept_cd
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
select induty_nm, count(*)
|
|
|
|
|
from tb_bssh_info
|
|
|
|
|
group by induty_nm;
|
|
|
|
|
|
|
|
|
|
select nrcd_se_nm, count(prduct_cd)
|
|
|
|
|
from tb_prduct_info
|
|
|
|
|
group by nrcd_se_nm;
|
|
|
|
|
select prtm_se_nm, count(prduct_cd)
|
|
|
|
|
from tb_prduct_info
|
|
|
|
|
group by prtm_se_nm;
|
|
|
|
|
|
|
|
|
|
SELECT tgt.dept_cd
|
|
|
|
|
, SUM(tgt.대마) AS '대마'
|
|
|
|
|
, SUM(tgt.마약) AS '마약'
|
|
|
|
|
, SUM(tgt.한외마약) AS '한외마약'
|
|
|
|
|
, SUM(tgt.향정) AS '향정'
|
|
|
|
|
, SUM(tgt.향정제외) AS '향정제외'
|
|
|
|
|
, SUM(tgt.기타) AS '기타'
|
|
|
|
|
, SUM(tgt.비마약류) AS '비마약류'
|
|
|
|
|
, SUM(tgt.일반관리대상) AS '일반관리대상'
|
|
|
|
|
, SUM(tgt.중점관리대상) AS '중점관리대상'
|
|
|
|
|
FROM (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.prtm_se_nm = '비마약류', 1, 0) AS '비마약류'
|
|
|
|
|
, IF(tpi.prtm_se_nm = '일반관리대상', 1, 0) AS '일반관리대상'
|
|
|
|
|
, IF(tpi.prtm_se_nm = '중점관리대상', 1, 0) AS '중점관리대상'
|
|
|
|
|
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
|
|
|
|
|
) tgt
|
|
|
|
|
GROUP BY tgt.dept_cd
|
|
|
|
|
UNION ALL
|
|
|
|
|
SELECT 'TOTAL' AS dept_cd
|
|
|
|
|
, SUM(tgt.대마) AS '대마'
|
|
|
|
|
, SUM(tgt.마약) AS '마약'
|
|
|
|
|
, SUM(tgt.한외마약) AS '한외마약'
|
|
|
|
|
, SUM(tgt.향정) AS '향정'
|
|
|
|
|
, SUM(tgt.향정제외) AS '향정제외'
|
|
|
|
|
, SUM(tgt.기타) AS '기타'
|
|
|
|
|
, SUM(tgt.비마약류) AS '비마약류'
|
|
|
|
|
, SUM(tgt.일반관리대상) AS '일반관리대상'
|
|
|
|
|
, SUM(tgt.중점관리대상) AS '중점관리대상'
|
|
|
|
|
FROM (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.prtm_se_nm = '비마약류', 1, 0) AS '비마약류'
|
|
|
|
|
, IF(tpi.prtm_se_nm = '일반관리대상', 1, 0) AS '일반관리대상'
|
|
|
|
|
, IF(tpi.prtm_se_nm = '중점관리대상', 1, 0) AS '중점관리대상'
|
|
|
|
|
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) tgt
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
|