연령별 옵션 추가(60대이상,4050대,30대이하)
This commit is contained in:
@@ -11,33 +11,33 @@
|
|||||||
<select id="getArea" resultMap="AnalysisVo">
|
<select id="getArea" resultMap="AnalysisVo">
|
||||||
SELECT SD.sido_cd, SD.sido_nm,
|
SELECT SD.sido_cd, SD.sido_nm,
|
||||||
AR.area_cd, AR.area_nm
|
AR.area_cd, AR.area_nm
|
||||||
FROM exitpoll_2022le.dbo.F_sido SD LEFT JOIN exitpoll_2022le.dbo.F_area AR
|
FROM exitpoll.dbo.F_sido SD LEFT JOIN exitpoll.dbo.F_area AR
|
||||||
ON SD.sido_cd = AR.sido_cd
|
ON SD.sido_cd = AR.sido_cd
|
||||||
WHERE AR.company = 'KRI'
|
WHERE AR.company = 'KRI'
|
||||||
ORDER BY SD.sido_cd, AR.area_cd
|
ORDER BY SD.sido_cd, AR.area_cd
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="getTimeBand" resultMap="AnalysisVo">
|
<select id="getTimeBand" resultMap="AnalysisVo">
|
||||||
SELECT * FROM exitpoll_2022le.dbo.F_TIME WHERE time_band > '0'
|
SELECT * FROM exitpoll.dbo.F_TIME WHERE time_band > '0'
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="getWeight" resultMap="AnalysisVo">
|
<select id="getWeight" resultMap="AnalysisVo">
|
||||||
SELECT area_cd, cluster, poll_pre, poll_5p, poll_5n
|
SELECT area_cd, cluster, poll_pre, poll_5p, poll_5n
|
||||||
FROM exitpoll_2022le.dbo.F_weight
|
FROM exitpoll.dbo.F_weight
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="getOption" resultMap="AnalysisVo1,AnalysisVo2">
|
<select id="getOption" resultMap="AnalysisVo1,AnalysisVo2">
|
||||||
SELECT vote_cd, option_cd, option_nm ,ROW_NUMBER() OVER (ORDER BY CAST(vote_cd AS INT), CAST(sort AS INT)) AS order_no
|
SELECT vote_cd, option_cd, option_nm ,ROW_NUMBER() OVER (ORDER BY CAST(vote_cd AS INT), CAST(sort AS INT)) AS order_no
|
||||||
FROM exitpoll_2022le.dbo.F_option
|
FROM exitpoll.dbo.F_option
|
||||||
ORDER BY CAST(vote_cd AS INT), CAST(option_type AS INT), sort
|
ORDER BY CAST(vote_cd AS INT), CAST(option_type AS INT), sort
|
||||||
|
|
||||||
SELECT area_cd, vote_cd, cand_option_cd, party_option_cd, edu_option_cd
|
SELECT area_cd, vote_cd, cand_option_cd, party_option_cd, edu_option_cd
|
||||||
FROM exitpoll_2022le.dbo.F_output_option
|
FROM exitpoll.dbo.F_output_option
|
||||||
ORDER BY area_cd, vote_cd
|
ORDER BY area_cd, vote_cd
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<update id="optionSave">
|
<update id="optionSave">
|
||||||
UPDATE exitpoll_2022le.dbo.F_output_option
|
UPDATE exitpoll.dbo.F_output_option
|
||||||
<if test="f_cand_party == 'CAND'">
|
<if test="f_cand_party == 'CAND'">
|
||||||
set cand_option_cd = #{option_cd}
|
set cand_option_cd = #{option_cd}
|
||||||
</if>
|
</if>
|
||||||
@@ -54,22 +54,22 @@
|
|||||||
|
|
||||||
SET NOCOUNT ON
|
SET NOCOUNT ON
|
||||||
-- @@@@@ 1. 테이블 F_TMP_EXPOLL을 비롯한 템프 테이블들을 Drop한다
|
-- @@@@@ 1. 테이블 F_TMP_EXPOLL을 비롯한 템프 테이블들을 Drop한다
|
||||||
DROP TABLE IF EXISTS exitpoll_2022le.dbo.F_TMP_EXPOLL
|
DROP TABLE IF EXISTS exitpoll.dbo.F_TMP_EXPOLL
|
||||||
DROP TABLE IF EXISTS exitpoll_2022le.dbo.TMP_EXIT_POLL
|
DROP TABLE IF EXISTS exitpoll.dbo.TMP_EXIT_POLL
|
||||||
DROP TABLE IF EXISTS exitpoll_2022le.dbo.TMP_GENDER_AGE
|
DROP TABLE IF EXISTS exitpoll.dbo.TMP_GENDER_AGE
|
||||||
DROP TABLE IF EXISTS exitpoll_2022le.dbo.TMP_GENDER_AGE_RATE
|
DROP TABLE IF EXISTS exitpoll.dbo.TMP_GENDER_AGE_RATE
|
||||||
DROP TABLE IF EXISTS exitpoll_2022le.dbo.TMP_GENDER_AGE_SUM
|
DROP TABLE IF EXISTS exitpoll.dbo.TMP_GENDER_AGE_SUM
|
||||||
DROP TABLE IF EXISTS exitpoll_2022le.dbo.TMP_CLUSTER_POLL
|
DROP TABLE IF EXISTS exitpoll.dbo.TMP_CLUSTER_POLL
|
||||||
DROP TABLE IF EXISTS exitpoll_2022le.dbo.TMP_CLUSTER_GA_SUM
|
DROP TABLE IF EXISTS exitpoll.dbo.TMP_CLUSTER_GA_SUM
|
||||||
DROP TABLE IF EXISTS exitpoll_2022le.dbo.TMP_CLUSTER_DATA
|
DROP TABLE IF EXISTS exitpoll.dbo.TMP_CLUSTER_DATA
|
||||||
DROP TABLE IF EXISTS exitpoll_2022le.dbo.TMP_WEIGHT_GA
|
DROP TABLE IF EXISTS exitpoll.dbo.TMP_WEIGHT_GA
|
||||||
DROP TABLE IF EXISTS exitpoll_2022le.dbo.TMP_PRE_P5N_CNT
|
DROP TABLE IF EXISTS exitpoll.dbo.TMP_PRE_P5N_CNT
|
||||||
DROP TABLE IF EXISTS exitpoll_2022le.dbo.TMP_PRE_P5N_RATIO;
|
DROP TABLE IF EXISTS exitpoll.dbo.TMP_PRE_P5N_RATIO;
|
||||||
|
|
||||||
-- @@@@@ 2. F_EXITPOLL에서 선택된 차수 보다 작거나 같은 Data를 F_TMP_EXPOLL에 넣는다
|
-- @@@@@ 2. F_EXITPOLL에서 선택된 차수 보다 작거나 같은 Data를 F_TMP_EXPOLL에 넣는다
|
||||||
SELECT a.* INTO exitpoll_2022le.dbo.F_TMP_EXPOLL
|
SELECT a.* INTO exitpoll.dbo.F_TMP_EXPOLL
|
||||||
FROM exitpoll_2022le.dbo.F_EXITPOLL a
|
FROM exitpoll.dbo.F_EXITPOLL a
|
||||||
left join exitpoll_2022le.dbo.F_cand c on a.area_cd=c.area_cd and a.cand_cd=c.cand_cd and c.quit = 0
|
left join exitpoll.dbo.F_cand c on a.area_cd=c.area_cd and a.cand_cd=c.cand_cd and c.quit = 0
|
||||||
<!-- WHERE #{time_band} >= a.time_band AND a.time_band != '0' and c.cand_cd is not null -->
|
<!-- WHERE #{time_band} >= a.time_band AND a.time_band != '0' and c.cand_cd is not null -->
|
||||||
WHERE #{time_band} >= a.time_band AND a.time_band != '0'
|
WHERE #{time_band} >= a.time_band AND a.time_band != '0'
|
||||||
and (a.cand_cd = '00' or c.cand_cd is not null) -- 무응답도 조회
|
and (a.cand_cd = '00' or c.cand_cd is not null) -- 무응답도 조회
|
||||||
@@ -80,18 +80,18 @@
|
|||||||
SELECT B.area_cd, B.subarea_cd,
|
SELECT B.area_cd, B.subarea_cd,
|
||||||
B.gender, B.age, cand_party,
|
B.gender, B.age, cand_party,
|
||||||
ISNULL(T.cand_party_cd, B.cand_party_cd) AS cand_party_cd, ISNULL(T.cnt, 0) AS cnt
|
ISNULL(T.cand_party_cd, B.cand_party_cd) AS cand_party_cd, ISNULL(T.cnt, 0) AS cnt
|
||||||
INTO exitpoll_2022le.dbo.TMP_EXIT_POLL
|
INTO exitpoll.dbo.TMP_EXIT_POLL
|
||||||
FROM
|
FROM
|
||||||
(
|
(
|
||||||
SELECT A.area_cd, GA.gender, GA.age, SA.subarea_cd, CP.cand_party, CP.cand_party_cd
|
SELECT A.area_cd, GA.gender, GA.age, SA.subarea_cd, CP.cand_party, CP.cand_party_cd
|
||||||
FROM exitpoll_2022le.dbo.F_area A LEFT JOIN exitpoll_2022le.dbo.F_subarea SA
|
FROM exitpoll.dbo.F_area A LEFT JOIN exitpoll.dbo.F_subarea SA
|
||||||
ON A.area_cd = SA.area_cd LEFT JOIN (
|
ON A.area_cd = SA.area_cd LEFT JOIN (
|
||||||
SELECT 'CAND' AS cand_party, area_cd, cand_cd AS cand_party_cd
|
SELECT 'CAND' AS cand_party, area_cd, cand_cd AS cand_party_cd
|
||||||
FROM exitpoll_2022le.dbo.F_cand UNION ALL
|
FROM exitpoll.dbo.F_cand UNION ALL
|
||||||
SELECT 'PARTY' AS cand_party, '0000' AS area_cd, party_cd AS cand_party_cd
|
SELECT 'PARTY' AS cand_party, '0000' AS area_cd, party_cd AS cand_party_cd
|
||||||
FROM exitpoll_2022le.dbo.F_party WHERE party_yn = '1' UNION ALL
|
FROM exitpoll.dbo.F_party WHERE party_yn = '1' UNION ALL
|
||||||
SELECT 'EDU' AS cand_party, area_cd, edu_cd AS cand_party_cd
|
SELECT 'EDU' AS cand_party, area_cd, edu_cd AS cand_party_cd
|
||||||
FROM exitpoll_2022le.dbo.F_edu WHERE quit = '0' UNION ALL
|
FROM exitpoll.dbo.F_edu WHERE quit = '0' UNION ALL
|
||||||
SELECT 'CAND' AS cand_party, '0000' AS area_cd, '00' AS cand_party_cd UNION ALL
|
SELECT 'CAND' AS cand_party, '0000' AS area_cd, '00' AS cand_party_cd UNION ALL
|
||||||
SELECT 'PARTY' AS cand_party, '0000' AS area_cd, '00' AS cand_party_cd UNION ALL
|
SELECT 'PARTY' AS cand_party, '0000' AS area_cd, '00' AS cand_party_cd UNION ALL
|
||||||
SELECT 'EDU' AS cand_party, '0000' AS area_cd, '00' AS cand_party_cd
|
SELECT 'EDU' AS cand_party, '0000' AS area_cd, '00' AS cand_party_cd
|
||||||
@@ -129,7 +129,7 @@
|
|||||||
edu_cd
|
edu_cd
|
||||||
</if>
|
</if>
|
||||||
AS cand_party_cd, count(*) AS cnt
|
AS cand_party_cd, count(*) AS cnt
|
||||||
FROM exitpoll_2022le.dbo.F_TMP_EXPOLL
|
FROM exitpoll.dbo.F_TMP_EXPOLL
|
||||||
WHERE 1=1
|
WHERE 1=1
|
||||||
<if test="f_local == 'CHOICE'">
|
<if test="f_local == 'CHOICE'">
|
||||||
AND area_cd = #{area_cd}
|
AND area_cd = #{area_cd}
|
||||||
@@ -155,17 +155,17 @@
|
|||||||
-- 선거구 X 층 - 계층별 집계 자료
|
-- 선거구 X 층 - 계층별 집계 자료
|
||||||
-- DROP TABLE TMP_GENDER_AGE
|
-- DROP TABLE TMP_GENDER_AGE
|
||||||
SELECT TEP.area_cd, cluster, cluster_nm, gender, age, TEP.cand_party, TEP.cand_party_cd, SUM(cnt) AS cnt
|
SELECT TEP.area_cd, cluster, cluster_nm, gender, age, TEP.cand_party, TEP.cand_party_cd, SUM(cnt) AS cnt
|
||||||
INTO exitpoll_2022le.dbo.TMP_GENDER_AGE
|
INTO exitpoll.dbo.TMP_GENDER_AGE
|
||||||
FROM
|
FROM
|
||||||
exitpoll_2022le.dbo.TMP_EXIT_POLL TEP LEFT JOIN exitpoll_2022le.dbo.F_subarea SA
|
exitpoll.dbo.TMP_EXIT_POLL TEP LEFT JOIN exitpoll.dbo.F_subarea SA
|
||||||
ON TEP.area_cd = SA.area_cd AND TEP.subarea_cd = SA.subarea_cd
|
ON TEP.area_cd = SA.area_cd AND TEP.subarea_cd = SA.subarea_cd
|
||||||
<if test="f_cand_party == 'CAND'">
|
<if test="f_cand_party == 'CAND'">
|
||||||
LEFT JOIN exitpoll_2022le.dbo.F_cand C ON TEP.area_cd = C.area_cd AND TEP.cand_party_cd = C.cand_cd
|
LEFT JOIN exitpoll.dbo.F_cand C ON TEP.area_cd = C.area_cd AND TEP.cand_party_cd = C.cand_cd
|
||||||
</if>
|
</if>
|
||||||
<if test="f_cand_party == 'EDU'">
|
<if test="f_cand_party == 'EDU'">
|
||||||
LEFT JOIN exitpoll_2022le.dbo.F_edu E ON TEP.area_cd = E.area_cd AND TEP.cand_party_cd = E.edu_cd AND E.quit = '0'
|
LEFT JOIN exitpoll.dbo.F_edu E ON TEP.area_cd = E.area_cd AND TEP.cand_party_cd = E.edu_cd AND E.quit = '0'
|
||||||
</if>
|
</if>
|
||||||
LEFT JOIN exitpoll_2022le.dbo.F_party P ON
|
LEFT JOIN exitpoll.dbo.F_party P ON
|
||||||
<if test="f_cand_party == 'CAND'"> C.party_cd </if>
|
<if test="f_cand_party == 'CAND'"> C.party_cd </if>
|
||||||
<if test="f_cand_party == 'PARTY'"> TEP.cand_party_cd </if>
|
<if test="f_cand_party == 'PARTY'"> TEP.cand_party_cd </if>
|
||||||
<if test="f_cand_party == 'EDU'"> '99' </if>
|
<if test="f_cand_party == 'EDU'"> '99' </if>
|
||||||
@@ -177,8 +177,8 @@
|
|||||||
-- 선거구 X 층 - 계층 응답자 집계합 (계층 무응답자 배분용)
|
-- 선거구 X 층 - 계층 응답자 집계합 (계층 무응답자 배분용)
|
||||||
-- DROP TABLE TMP_GENDER_AGE_SUM
|
-- DROP TABLE TMP_GENDER_AGE_SUM
|
||||||
SELECT area_cd, cluster, cluster_nm, cand_party_cd, SUM(cnt) AS cnt
|
SELECT area_cd, cluster, cluster_nm, cand_party_cd, SUM(cnt) AS cnt
|
||||||
INTO exitpoll_2022le.dbo.TMP_GENDER_AGE_SUM
|
INTO exitpoll.dbo.TMP_GENDER_AGE_SUM
|
||||||
FROM exitpoll_2022le.dbo.TMP_GENDER_AGE
|
FROM exitpoll.dbo.TMP_GENDER_AGE
|
||||||
WHERE gender != '0' AND age != '0'
|
WHERE gender != '0' AND age != '0'
|
||||||
GROUP BY area_cd, cluster, cluster_nm, cand_party_cd
|
GROUP BY area_cd, cluster, cluster_nm, cand_party_cd
|
||||||
|
|
||||||
@@ -188,8 +188,8 @@
|
|||||||
-- DROP TABLE TMP_GENDER_AGE_RATE
|
-- DROP TABLE TMP_GENDER_AGE_RATE
|
||||||
SELECT GA.area_cd, GA.cluster, GA.cluster_nm, gender, age, GA.cand_party_cd,
|
SELECT GA.area_cd, GA.cluster, GA.cluster_nm, gender, age, GA.cand_party_cd,
|
||||||
CASE SGA.cnt WHEN 0 THEN 0.0 ELSE GA.cnt * 1.0 / SGA.cnt END AS vote_rate
|
CASE SGA.cnt WHEN 0 THEN 0.0 ELSE GA.cnt * 1.0 / SGA.cnt END AS vote_rate
|
||||||
INTO exitpoll_2022le.dbo.TMP_GENDER_AGE_RATE
|
INTO exitpoll.dbo.TMP_GENDER_AGE_RATE
|
||||||
FROM exitpoll_2022le.dbo.TMP_GENDER_AGE GA LEFT JOIN exitpoll_2022le.dbo.TMP_GENDER_AGE_SUM SGA
|
FROM exitpoll.dbo.TMP_GENDER_AGE GA LEFT JOIN exitpoll.dbo.TMP_GENDER_AGE_SUM SGA
|
||||||
ON GA.area_cd = SGA.area_cd AND GA.cluster = SGA.cluster AND GA.cand_party_cd = SGA.cand_party_cd
|
ON GA.area_cd = SGA.area_cd AND GA.cluster = SGA.cluster AND GA.cand_party_cd = SGA.cand_party_cd
|
||||||
WHERE gender != '0' AND age != '0'
|
WHERE gender != '0' AND age != '0'
|
||||||
|
|
||||||
@@ -200,27 +200,27 @@
|
|||||||
|
|
||||||
|
|
||||||
SELECT area_cd, cluster, cluster_nm, gender, age, cand_party, cand_party_cd, sum(cnt) AS cnt
|
SELECT area_cd, cluster, cluster_nm, gender, age, cand_party, cand_party_cd, sum(cnt) AS cnt
|
||||||
INTO exitpoll_2022le.dbo.TMP_CLUSTER_POLL
|
INTO exitpoll.dbo.TMP_CLUSTER_POLL
|
||||||
FROM
|
FROM
|
||||||
(
|
(
|
||||||
/* 성/연령 응답자 */
|
/* 성/연령 응답자 */
|
||||||
SELECT area_cd, cluster, cluster_nm, gender, age, cand_party, cand_party_cd, cnt
|
SELECT area_cd, cluster, cluster_nm, gender, age, cand_party, cand_party_cd, cnt
|
||||||
FROM exitpoll_2022le.dbo.TMP_GENDER_AGE
|
FROM exitpoll.dbo.TMP_GENDER_AGE
|
||||||
WHERE gender != '0' AND age != '0'
|
WHERE gender != '0' AND age != '0'
|
||||||
/* 성/연령 무응답자 배분 */ UNION ALL
|
/* 성/연령 무응답자 배분 */ UNION ALL
|
||||||
SELECT GA.area_cd, GA.cluster, GA.cluster_nm, GAR.gender, GAR.age, cand_party, GA.cand_party_cd, (GA.cnt * vote_rate) AS calc_cnt
|
SELECT GA.area_cd, GA.cluster, GA.cluster_nm, GAR.gender, GAR.age, cand_party, GA.cand_party_cd, (GA.cnt * vote_rate) AS calc_cnt
|
||||||
FROM exitpoll_2022le.dbo.TMP_GENDER_AGE GA LEFT JOIN exitpoll_2022le.dbo.TMP_GENDER_AGE_RATE GAR
|
FROM exitpoll.dbo.TMP_GENDER_AGE GA LEFT JOIN exitpoll.dbo.TMP_GENDER_AGE_RATE GAR
|
||||||
ON GA.area_cd = GAR.area_cd AND GA.cluster = GAR.cluster AND GA.cand_party_cd = GAR.cand_party_cd
|
ON GA.area_cd = GAR.area_cd AND GA.cluster = GAR.cluster AND GA.cand_party_cd = GAR.cand_party_cd
|
||||||
WHERE GA.gender = '0' AND GA.age = '0'
|
WHERE GA.gender = '0' AND GA.age = '0'
|
||||||
/* 성 무응답자 배분 */ UNION ALL
|
/* 성 무응답자 배분 */ UNION ALL
|
||||||
SELECT GA.area_cd, GA.cluster, GA.cluster_nm, GAR.gender, GA.age, cand_party, GA.cand_party_cd, (GA.cnt * SUM(vote_rate)) AS calc_cnt
|
SELECT GA.area_cd, GA.cluster, GA.cluster_nm, GAR.gender, GA.age, cand_party, GA.cand_party_cd, (GA.cnt * SUM(vote_rate)) AS calc_cnt
|
||||||
FROM exitpoll_2022le.dbo.TMP_GENDER_AGE GA LEFT JOIN exitpoll_2022le.dbo.TMP_GENDER_AGE_RATE GAR
|
FROM exitpoll.dbo.TMP_GENDER_AGE GA LEFT JOIN exitpoll.dbo.TMP_GENDER_AGE_RATE GAR
|
||||||
ON GA.area_cd = GAR.area_cd AND GA.cluster = GAR.cluster AND GA.cand_party_cd = GAR.cand_party_cd
|
ON GA.area_cd = GAR.area_cd AND GA.cluster = GAR.cluster AND GA.cand_party_cd = GAR.cand_party_cd
|
||||||
WHERE GA.gender = '0' AND GA.age != '0'
|
WHERE GA.gender = '0' AND GA.age != '0'
|
||||||
GROUP BY GA.area_cd, GA.cluster, GA.cluster_nm, GAR.gender, GA.age, cand_party, GA.cand_party_cd, GA.cnt
|
GROUP BY GA.area_cd, GA.cluster, GA.cluster_nm, GAR.gender, GA.age, cand_party, GA.cand_party_cd, GA.cnt
|
||||||
/* 연령 무응답자 배분 */ UNION ALL
|
/* 연령 무응답자 배분 */ UNION ALL
|
||||||
SELECT GA.area_cd, GA.cluster, GA.cluster_nm, GA.gender, GAR.age, cand_party, GA.cand_party_cd, (GA.cnt * SUM(vote_rate)) AS calc_cnt
|
SELECT GA.area_cd, GA.cluster, GA.cluster_nm, GA.gender, GAR.age, cand_party, GA.cand_party_cd, (GA.cnt * SUM(vote_rate)) AS calc_cnt
|
||||||
FROM exitpoll_2022le.dbo.TMP_GENDER_AGE GA LEFT JOIN exitpoll_2022le.dbo.TMP_GENDER_AGE_RATE GAR
|
FROM exitpoll.dbo.TMP_GENDER_AGE GA LEFT JOIN exitpoll.dbo.TMP_GENDER_AGE_RATE GAR
|
||||||
ON GA.area_cd = GAR.area_cd AND GA.cluster = GAR.cluster AND GA.cand_party_cd = GAR.cand_party_cd
|
ON GA.area_cd = GAR.area_cd AND GA.cluster = GAR.cluster AND GA.cand_party_cd = GAR.cand_party_cd
|
||||||
WHERE GA.gender != '0' AND GA.age = '0'
|
WHERE GA.gender != '0' AND GA.age = '0'
|
||||||
GROUP BY GA.area_cd, GA.cluster, GA.cluster_nm, GA.gender, GAR.age, cand_party, GA.cand_party_cd, GA.cnt
|
GROUP BY GA.area_cd, GA.cluster, GA.cluster_nm, GA.gender, GAR.age, cand_party, GA.cand_party_cd, GA.cnt
|
||||||
@@ -231,8 +231,8 @@
|
|||||||
-- 선거구 X 층 - 계층 응답자 집계합 (계층별 득표율 구하기 위함)
|
-- 선거구 X 층 - 계층 응답자 집계합 (계층별 득표율 구하기 위함)
|
||||||
|
|
||||||
SELECT area_cd, cluster, cluster_nm, gender, age, sum(cnt) AS cnt
|
SELECT area_cd, cluster, cluster_nm, gender, age, sum(cnt) AS cnt
|
||||||
INTO exitpoll_2022le.dbo.TMP_CLUSTER_GA_SUM
|
INTO exitpoll.dbo.TMP_CLUSTER_GA_SUM
|
||||||
FROM exitpoll_2022le.dbo.TMP_CLUSTER_POLL
|
FROM exitpoll.dbo.TMP_CLUSTER_POLL
|
||||||
GROUP BY area_cd, cluster, cluster_nm, gender, age
|
GROUP BY area_cd, cluster, cluster_nm, gender, age
|
||||||
|
|
||||||
-- @@@@@ 9. TMP_CLUSTER_GA_SUM, TMP_CLUSTER_POLL을 사용하여 지역 X 층 X 계층 X 후보(정당) 득표수, 계층별 득표수 합을 TMP_CLUSTER_DATA에 넣는다
|
-- @@@@@ 9. TMP_CLUSTER_GA_SUM, TMP_CLUSTER_POLL을 사용하여 지역 X 층 X 계층 X 후보(정당) 득표수, 계층별 득표수 합을 TMP_CLUSTER_DATA에 넣는다
|
||||||
@@ -240,7 +240,7 @@
|
|||||||
-- 선거구 X 층 - 계층별 득표수, 계층별 득표수 합, 계층별 득표율
|
-- 선거구 X 층 - 계층별 득표수, 계층별 득표수 합, 계층별 득표율
|
||||||
|
|
||||||
SELECT area_cd, cluster, cluster_nm, sect, cand_party, cand_party_cd, sum_cnt, cnt
|
SELECT area_cd, cluster, cluster_nm, sect, cand_party, cand_party_cd, sum_cnt, cnt
|
||||||
INTO exitpoll_2022le.dbo.TMP_CLUSTER_DATA
|
INTO exitpoll.dbo.TMP_CLUSTER_DATA
|
||||||
FROM
|
FROM
|
||||||
(
|
(
|
||||||
/* 해당 층의 전체 득표수, 후보(정당)별 득표수 */
|
/* 해당 층의 전체 득표수, 후보(정당)별 득표수 */
|
||||||
@@ -250,12 +250,12 @@
|
|||||||
FROM
|
FROM
|
||||||
(
|
(
|
||||||
SELECT area_cd, cluster, cluster_nm, sum(cnt) AS cnt
|
SELECT area_cd, cluster, cluster_nm, sum(cnt) AS cnt
|
||||||
FROM exitpoll_2022le.dbo.TMP_CLUSTER_GA_SUM
|
FROM exitpoll.dbo.TMP_CLUSTER_GA_SUM
|
||||||
GROUP BY area_cd, cluster, cluster_nm
|
GROUP BY area_cd, cluster, cluster_nm
|
||||||
) CGS LEFT JOIN
|
) CGS LEFT JOIN
|
||||||
(
|
(
|
||||||
SELECT area_cd, cluster, cluster_nm, cand_party, cand_party_cd, sum(cnt) AS cnt
|
SELECT area_cd, cluster, cluster_nm, cand_party, cand_party_cd, sum(cnt) AS cnt
|
||||||
FROM exitpoll_2022le.dbo.TMP_CLUSTER_POLL
|
FROM exitpoll.dbo.TMP_CLUSTER_POLL
|
||||||
GROUP BY area_cd, cluster, cluster_nm, cand_party, cand_party_cd
|
GROUP BY area_cd, cluster, cluster_nm, cand_party, cand_party_cd
|
||||||
) CP
|
) CP
|
||||||
ON CGS.area_cd = CP.area_cd AND CGS.cluster = CP.cluster
|
ON CGS.area_cd = CP.area_cd AND CGS.cluster = CP.cluster
|
||||||
@@ -266,12 +266,12 @@
|
|||||||
FROM
|
FROM
|
||||||
(
|
(
|
||||||
SELECT area_cd, cluster, cluster_nm, gender, sum(cnt) AS cnt
|
SELECT area_cd, cluster, cluster_nm, gender, sum(cnt) AS cnt
|
||||||
FROM exitpoll_2022le.dbo.TMP_CLUSTER_GA_SUM
|
FROM exitpoll.dbo.TMP_CLUSTER_GA_SUM
|
||||||
GROUP BY area_cd, cluster, cluster_nm, gender
|
GROUP BY area_cd, cluster, cluster_nm, gender
|
||||||
) CGS LEFT JOIN
|
) CGS LEFT JOIN
|
||||||
(
|
(
|
||||||
SELECT area_cd, cluster, cluster_nm, gender, cand_party, cand_party_cd, sum(cnt) AS cnt
|
SELECT area_cd, cluster, cluster_nm, gender, cand_party, cand_party_cd, sum(cnt) AS cnt
|
||||||
FROM exitpoll_2022le.dbo.TMP_CLUSTER_POLL
|
FROM exitpoll.dbo.TMP_CLUSTER_POLL
|
||||||
GROUP BY area_cd, cluster, cluster_nm, gender, cand_party, cand_party_cd
|
GROUP BY area_cd, cluster, cluster_nm, gender, cand_party, cand_party_cd
|
||||||
) CP
|
) CP
|
||||||
ON CGS.area_cd = CP.area_cd AND CGS.cluster = CP.cluster AND CGS.gender = CP.gender
|
ON CGS.area_cd = CP.area_cd AND CGS.cluster = CP.cluster AND CGS.gender = CP.gender
|
||||||
@@ -288,12 +288,12 @@
|
|||||||
FROM
|
FROM
|
||||||
(
|
(
|
||||||
SELECT area_cd, cluster, cluster_nm, age, sum(cnt) AS cnt
|
SELECT area_cd, cluster, cluster_nm, age, sum(cnt) AS cnt
|
||||||
FROM exitpoll_2022le.dbo.TMP_CLUSTER_GA_SUM
|
FROM exitpoll.dbo.TMP_CLUSTER_GA_SUM
|
||||||
GROUP BY area_cd, cluster, cluster_nm, age
|
GROUP BY area_cd, cluster, cluster_nm, age
|
||||||
) CGS LEFT JOIN
|
) CGS LEFT JOIN
|
||||||
(
|
(
|
||||||
SELECT area_cd, cluster, cluster_nm, age, cand_party, cand_party_cd, sum(cnt) AS cnt
|
SELECT area_cd, cluster, cluster_nm, age, cand_party, cand_party_cd, sum(cnt) AS cnt
|
||||||
FROM exitpoll_2022le.dbo.TMP_CLUSTER_POLL
|
FROM exitpoll.dbo.TMP_CLUSTER_POLL
|
||||||
GROUP BY area_cd, cluster, cluster_nm, age, cand_party, cand_party_cd
|
GROUP BY area_cd, cluster, cluster_nm, age, cand_party, cand_party_cd
|
||||||
) CP
|
) CP
|
||||||
ON CGS.area_cd = CP.area_cd AND CGS.cluster = CP.cluster AND CGS.age = CP.age
|
ON CGS.area_cd = CP.area_cd AND CGS.cluster = CP.cluster AND CGS.age = CP.age
|
||||||
@@ -319,12 +319,12 @@
|
|||||||
FROM
|
FROM
|
||||||
(
|
(
|
||||||
SELECT area_cd, cluster, cluster_nm, gender, age, sum(cnt) AS cnt
|
SELECT area_cd, cluster, cluster_nm, gender, age, sum(cnt) AS cnt
|
||||||
FROM exitpoll_2022le.dbo.TMP_CLUSTER_GA_SUM
|
FROM exitpoll.dbo.TMP_CLUSTER_GA_SUM
|
||||||
GROUP BY area_cd, cluster, cluster_nm, gender, age
|
GROUP BY area_cd, cluster, cluster_nm, gender, age
|
||||||
) CGS LEFT JOIN
|
) CGS LEFT JOIN
|
||||||
(
|
(
|
||||||
SELECT area_cd, cluster, cluster_nm, gender, age, cand_party, cand_party_cd, sum(cnt) AS cnt
|
SELECT area_cd, cluster, cluster_nm, gender, age, cand_party, cand_party_cd, sum(cnt) AS cnt
|
||||||
FROM exitpoll_2022le.dbo.TMP_CLUSTER_POLL
|
FROM exitpoll.dbo.TMP_CLUSTER_POLL
|
||||||
GROUP BY area_cd, cluster, cluster_nm, gender, age, cand_party, cand_party_cd
|
GROUP BY area_cd, cluster, cluster_nm, gender, age, cand_party, cand_party_cd
|
||||||
) CP
|
) CP
|
||||||
ON CGS.area_cd = CP.area_cd AND CGS.cluster = CP.cluster AND CGS.gender = CP.gender AND CGS.age = CP.age
|
ON CGS.area_cd = CP.area_cd AND CGS.cluster = CP.cluster AND CGS.gender = CP.gender AND CGS.age = CP.age
|
||||||
@@ -344,7 +344,7 @@
|
|||||||
WHEN 'w' THEN 19 END), 2) AS sect,
|
WHEN 'w' THEN 19 END), 2) AS sect,
|
||||||
CONVERT(NUMERIC(12, 10), pre_ratio) AS pre_ratio,
|
CONVERT(NUMERIC(12, 10), pre_ratio) AS pre_ratio,
|
||||||
CONVERT(NUMERIC(12, 10), p5n_ratio) AS p5n_ratio
|
CONVERT(NUMERIC(12, 10), p5n_ratio) AS p5n_ratio
|
||||||
INTO exitpoll_2022le.dbo.TMP_WEIGHT_GA
|
INTO exitpoll.dbo.TMP_WEIGHT_GA
|
||||||
FROM
|
FROM
|
||||||
(
|
(
|
||||||
SELECT area_cd, cluster,
|
SELECT area_cd, cluster,
|
||||||
@@ -357,7 +357,7 @@
|
|||||||
-- 5시이후 20대 여 ~ 70 여 가중치
|
-- 5시이후 20대 여 ~ 70 여 가중치
|
||||||
p5n_20_w, p5n_30_w, p5n_40_w, p5n_50_w, p5n_60_w, p5n_70_w
|
p5n_20_w, p5n_30_w, p5n_40_w, p5n_50_w, p5n_60_w, p5n_70_w
|
||||||
|
|
||||||
FROM exitpoll_2022le.dbo.F_weight
|
FROM exitpoll.dbo.F_weight
|
||||||
) T
|
) T
|
||||||
UNPIVOT
|
UNPIVOT
|
||||||
(
|
(
|
||||||
@@ -382,19 +382,19 @@
|
|||||||
SELECT A.area_cd, A.cluster, A.sect,
|
SELECT A.area_cd, A.cluster, A.sect,
|
||||||
CASE A.cnt WHEN 0 THEN 0.0 ELSE WGA.pre_ratio / (A.cnt / B.sum_cnt) END AS pre_ratio,
|
CASE A.cnt WHEN 0 THEN 0.0 ELSE WGA.pre_ratio / (A.cnt / B.sum_cnt) END AS pre_ratio,
|
||||||
CASE A.cnt WHEN 0 THEN 0.0 ELSE WGA.p5n_ratio / (A.cnt / B.sum_cnt) END AS p5n_ratio
|
CASE A.cnt WHEN 0 THEN 0.0 ELSE WGA.p5n_ratio / (A.cnt / B.sum_cnt) END AS p5n_ratio
|
||||||
INTO exitpoll_2022le.dbo.TMP_PRE_P5N_RATIO
|
INTO exitpoll.dbo.TMP_PRE_P5N_RATIO
|
||||||
FROM
|
FROM
|
||||||
(
|
(
|
||||||
SELECT area_cd, cluster, LEFT(sect, 2) AS sect, SUM(cnt) AS cnt
|
SELECT area_cd, cluster, LEFT(sect, 2) AS sect, SUM(cnt) AS cnt
|
||||||
FROM exitpoll_2022le.dbo.TMP_CLUSTER_DATA
|
FROM exitpoll.dbo.TMP_CLUSTER_DATA
|
||||||
WHERE (LEFT(sect, 2) BETWEEN '11' AND '16' OR LEFT(sect, 2) BETWEEN '21' AND '26') AND cand_party_cd != '00'
|
WHERE (LEFT(sect, 2) BETWEEN '11' AND '16' OR LEFT(sect, 2) BETWEEN '21' AND '26') AND cand_party_cd != '00'
|
||||||
GROUP BY area_cd, cluster, LEFT(sect, 2)
|
GROUP BY area_cd, cluster, LEFT(sect, 2)
|
||||||
) A LEFT JOIN (
|
) A LEFT JOIN (
|
||||||
SELECT area_cd, cluster, SUM(cnt) AS sum_cnt
|
SELECT area_cd, cluster, SUM(cnt) AS sum_cnt
|
||||||
FROM exitpoll_2022le.dbo.TMP_CLUSTER_DATA
|
FROM exitpoll.dbo.TMP_CLUSTER_DATA
|
||||||
WHERE LEFT(sect, 2) = '00' AND cand_party_cd != '00'
|
WHERE LEFT(sect, 2) = '00' AND cand_party_cd != '00'
|
||||||
GROUP BY area_cd, cluster
|
GROUP BY area_cd, cluster
|
||||||
) B ON A.area_cd = B.area_cd AND A.cluster = B.cluster LEFT JOIN exitpoll_2022le.dbo.TMP_WEIGHT_GA WGA
|
) B ON A.area_cd = B.area_cd AND A.cluster = B.cluster LEFT JOIN exitpoll.dbo.TMP_WEIGHT_GA WGA
|
||||||
ON A.area_cd = WGA.area_cd AND A.cluster = WGA.cluster AND A.sect = WGA.sect
|
ON A.area_cd = WGA.area_cd AND A.cluster = WGA.cluster AND A.sect = WGA.sect
|
||||||
|
|
||||||
-- @@@@@ 12. TMP_CLUSTER_DATA의 득표수에 계산된 TMP_PRE_P5N_RATIO의 가중치를 적용해서 TMP_PRE_P5N_CNT에 넣는다
|
-- @@@@@ 12. TMP_CLUSTER_DATA의 득표수에 계산된 TMP_PRE_P5N_RATIO의 가중치를 적용해서 TMP_PRE_P5N_CNT에 넣는다
|
||||||
@@ -403,30 +403,30 @@
|
|||||||
SELECT A.area_cd, A.cluster, A.cand_party, A.cand_party_cd, A.sect, A.sect_str, sum_cnt, n_cnt, cnt,
|
SELECT A.area_cd, A.cluster, A.cand_party, A.cand_party_cd, A.sect, A.sect_str, sum_cnt, n_cnt, cnt,
|
||||||
(sum_cnt-n_cnt) * B.pre_ratio AS pre_sum, cnt * B.pre_ratio AS pre_cnt,
|
(sum_cnt-n_cnt) * B.pre_ratio AS pre_sum, cnt * B.pre_ratio AS pre_cnt,
|
||||||
(sum_cnt-n_cnt) * B.p5n_ratio AS p5n_sum, cnt * B.p5n_ratio AS p5n_cnt
|
(sum_cnt-n_cnt) * B.p5n_ratio AS p5n_sum, cnt * B.p5n_ratio AS p5n_cnt
|
||||||
INTO exitpoll_2022le.dbo.TMP_PRE_P5N_CNT
|
INTO exitpoll.dbo.TMP_PRE_P5N_CNT
|
||||||
FROM
|
FROM
|
||||||
(
|
(
|
||||||
SELECT area_cd, cluster, cand_party, LEFT(sect, 2) AS sect, sect AS sect_str, cand_party_cd, sum_cnt, cnt
|
SELECT area_cd, cluster, cand_party, LEFT(sect, 2) AS sect, sect AS sect_str, cand_party_cd, sum_cnt, cnt
|
||||||
FROM exitpoll_2022le.dbo.TMP_CLUSTER_DATA
|
FROM exitpoll.dbo.TMP_CLUSTER_DATA
|
||||||
WHERE (LEFT(sect, 2) BETWEEN '11' AND '16' OR LEFT(sect, 2) BETWEEN '21' AND '26') AND cand_party_cd != '00'
|
WHERE (LEFT(sect, 2) BETWEEN '11' AND '16' OR LEFT(sect, 2) BETWEEN '21' AND '26') AND cand_party_cd != '00'
|
||||||
) A LEFT JOIN exitpoll_2022le.dbo.TMP_PRE_P5N_RATIO B ON A.area_cd = B.area_cd AND A.cluster = B.cluster AND A.sect = B.sect
|
) A LEFT JOIN exitpoll.dbo.TMP_PRE_P5N_RATIO B ON A.area_cd = B.area_cd AND A.cluster = B.cluster AND A.sect = B.sect
|
||||||
LEFT JOIN
|
LEFT JOIN
|
||||||
(
|
(
|
||||||
SELECT area_cd, cluster, LEFT(sect, 2) AS sect, sect AS sect_str, cnt AS n_cnt
|
SELECT area_cd, cluster, LEFT(sect, 2) AS sect, sect AS sect_str, cnt AS n_cnt
|
||||||
FROM exitpoll_2022le.dbo.TMP_CLUSTER_DATA
|
FROM exitpoll.dbo.TMP_CLUSTER_DATA
|
||||||
WHERE (LEFT(sect, 2) BETWEEN '11' AND '16' OR LEFT(sect, 2) BETWEEN '21' AND '26') AND cand_party_cd = '00'
|
WHERE (LEFT(sect, 2) BETWEEN '11' AND '16' OR LEFT(sect, 2) BETWEEN '21' AND '26') AND cand_party_cd = '00'
|
||||||
) C ON A.area_cd = C.area_cd AND A.cluster = C.cluster AND A.sect = C.sect
|
) C ON A.area_cd = C.area_cd AND A.cluster = C.cluster AND A.sect = C.sect
|
||||||
|
|
||||||
|
|
||||||
-- @@@@@ 13. TMP_OUTPUT_DDAY 초기화
|
-- @@@@@ 13. TMP_OUTPUT_DDAY 초기화
|
||||||
DELETE FROM exitpoll_2022le.dbo.TMP_OUTPUT_DDAY
|
DELETE FROM exitpoll.dbo.TMP_OUTPUT_DDAY
|
||||||
WHERE cand_party = #{f_cand_party}
|
WHERE cand_party = #{f_cand_party}
|
||||||
<if test="f_local == 'CHOICE'">
|
<if test="f_local == 'CHOICE'">
|
||||||
AND area_cd = #{area_cd}
|
AND area_cd = #{area_cd}
|
||||||
</if>
|
</if>
|
||||||
|
|
||||||
-- @@@@@ 14. TMP_PRE_P5N_CNT을 사용하여 층 X 후보(정당) X 옵션 별 count를 계산하여 TMP_OUTPUT_DDAY에 넣는다
|
-- @@@@@ 14. TMP_PRE_P5N_CNT을 사용하여 층 X 후보(정당) X 옵션 별 count를 계산하여 TMP_OUTPUT_DDAY에 넣는다
|
||||||
INSERT INTO exitpoll_2022le.dbo.TMP_OUTPUT_DDAY
|
INSERT INTO exitpoll.dbo.TMP_OUTPUT_DDAY
|
||||||
/*
|
/*
|
||||||
당일 옵션
|
당일 옵션
|
||||||
01 성연령 보정
|
01 성연령 보정
|
||||||
@@ -441,12 +441,12 @@
|
|||||||
(
|
(
|
||||||
-- 01. 후보(정당) 무응답 제외 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
-- 01. 후보(정당) 무응답 제외 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||||
SELECT area_cd, cluster, cand_party, sect, cand_party_cd, '01' AS option_cd, sum_cnt - n_cnt AS sum_cnt, cnt
|
SELECT area_cd, cluster, cand_party, sect, cand_party_cd, '01' AS option_cd, sum_cnt - n_cnt AS sum_cnt, cnt
|
||||||
FROM exitpoll_2022le.dbo.TMP_PRE_P5N_CNT
|
FROM exitpoll.dbo.TMP_PRE_P5N_CNT
|
||||||
UNION ALL
|
UNION ALL
|
||||||
-- 01.성연령 보정 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
-- 01.성연령 보정 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||||
SELECT area_cd, cluster, cand_party, sect, cand_party_cd, '02' AS option_cd, sum_cnt,
|
SELECT area_cd, cluster, cand_party, sect, cand_party_cd, '02' AS option_cd, sum_cnt,
|
||||||
CASE cnt WHEN 0 THEN 0 ELSE n_cnt * cnt / (sum_cnt - n_cnt) + cnt END AS cnt
|
CASE cnt WHEN 0 THEN 0 ELSE n_cnt * cnt / (sum_cnt - n_cnt) + cnt END AS cnt
|
||||||
FROM exitpoll_2022le.dbo.TMP_PRE_P5N_CNT
|
FROM exitpoll.dbo.TMP_PRE_P5N_CNT
|
||||||
UNION ALL
|
UNION ALL
|
||||||
-- 계층 별(성/연령)
|
-- 계층 별(성/연령)
|
||||||
-- 03.열세자 95%(성/연령) @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
-- 03.열세자 95%(성/연령) @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||||
@@ -468,18 +468,18 @@
|
|||||||
END
|
END
|
||||||
END
|
END
|
||||||
END AS cnt
|
END AS cnt
|
||||||
FROM exitpoll_2022le.dbo.TMP_PRE_P5N_CNT T LEFT JOIN (
|
FROM exitpoll.dbo.TMP_PRE_P5N_CNT T LEFT JOIN (
|
||||||
SELECT area_cd, cluster, cand_party, sect, cnt AS max_cnt FROM (
|
SELECT area_cd, cluster, cand_party, sect, cnt AS max_cnt FROM (
|
||||||
SELECT area_cd, cluster, cand_party, sect, cnt,
|
SELECT area_cd, cluster, cand_party, sect, cnt,
|
||||||
RANK() OVER(PARTITION BY area_cd, cluster, cand_party, sect ORDER BY cnt DESC) AS rnk
|
RANK() OVER(PARTITION BY area_cd, cluster, cand_party, sect ORDER BY cnt DESC) AS rnk
|
||||||
FROM exitpoll_2022le.dbo.TMP_PRE_P5N_CNT
|
FROM exitpoll.dbo.TMP_PRE_P5N_CNT
|
||||||
) MX
|
) MX
|
||||||
WHERE rnk = 1
|
WHERE rnk = 1
|
||||||
GROUP BY area_cd, cluster, cand_party, sect, cnt HAVING sum(rnk) = 1
|
GROUP BY area_cd, cluster, cand_party, sect, cnt HAVING sum(rnk) = 1
|
||||||
) MC ON T.area_cd = MC.area_cd AND T.cand_party = MC.cand_party AND T.cluster = MC.cluster AND T.sect = MC.sect LEFT JOIN
|
) MC ON T.area_cd = MC.area_cd AND T.cand_party = MC.cand_party AND T.cluster = MC.cluster AND T.sect = MC.sect LEFT JOIN
|
||||||
(
|
(
|
||||||
select weight_rate as weight, option_cd
|
select weight_rate as weight, option_cd
|
||||||
from exitpoll_2022le.dbo.F_option
|
from exitpoll.dbo.F_option
|
||||||
where vote_cd = 2
|
where vote_cd = 2
|
||||||
and option_type = 4
|
and option_type = 4
|
||||||
) W ON 1=1
|
) W ON 1=1
|
||||||
@@ -500,13 +500,13 @@
|
|||||||
END AS cnt
|
END AS cnt
|
||||||
FROM (
|
FROM (
|
||||||
SELECT area_cd, cluster, cand_party, cand_party_cd, sum(sum_cnt) AS sum_cnt, sum(n_cnt) AS n_cnt, sum(cnt) AS cnt
|
SELECT area_cd, cluster, cand_party, cand_party_cd, sum(sum_cnt) AS sum_cnt, sum(n_cnt) AS n_cnt, sum(cnt) AS cnt
|
||||||
FROM exitpoll_2022le.dbo.TMP_PRE_P5N_CNT
|
FROM exitpoll.dbo.TMP_PRE_P5N_CNT
|
||||||
GROUP BY area_cd, cluster, cand_party, cand_party_cd
|
GROUP BY area_cd, cluster, cand_party, cand_party_cd
|
||||||
) T LEFT JOIN (
|
) T LEFT JOIN (
|
||||||
SELECT area_cd, cluster, cand_party, cnt AS max_cnt FROM (
|
SELECT area_cd, cluster, cand_party, cnt AS max_cnt FROM (
|
||||||
SELECT area_cd, cluster, cand_party, sum(cnt) AS cnt,
|
SELECT area_cd, cluster, cand_party, sum(cnt) AS cnt,
|
||||||
RANK() OVER(PARTITION BY area_cd, cluster, cand_party ORDER BY sum(cnt) DESC) AS rnk
|
RANK() OVER(PARTITION BY area_cd, cluster, cand_party ORDER BY sum(cnt) DESC) AS rnk
|
||||||
FROM exitpoll_2022le.dbo.TMP_PRE_P5N_CNT
|
FROM exitpoll.dbo.TMP_PRE_P5N_CNT
|
||||||
GROUP BY area_cd, cluster, cand_party, cand_party_cd
|
GROUP BY area_cd, cluster, cand_party, cand_party_cd
|
||||||
) MX
|
) MX
|
||||||
WHERE rnk = 1
|
WHERE rnk = 1
|
||||||
@@ -514,7 +514,7 @@
|
|||||||
) MC ON T.area_cd = MC.area_cd AND T.cand_party = MC.cand_party AND T.cluster = MC.cluster LEFT JOIN
|
) MC ON T.area_cd = MC.area_cd AND T.cand_party = MC.cand_party AND T.cluster = MC.cluster LEFT JOIN
|
||||||
(
|
(
|
||||||
select weight_rate as weight, option_cd
|
select weight_rate as weight, option_cd
|
||||||
from exitpoll_2022le.dbo.F_option
|
from exitpoll.dbo.F_option
|
||||||
where vote_cd = 2
|
where vote_cd = 2
|
||||||
and option_type = 5
|
and option_type = 5
|
||||||
) W ON 1=1
|
) W ON 1=1
|
||||||
@@ -524,14 +524,14 @@
|
|||||||
</if>
|
</if>
|
||||||
|
|
||||||
-- @@@@@ 15. TMP_OUTPUT_PRE 초기화
|
-- @@@@@ 15. TMP_OUTPUT_PRE 초기화
|
||||||
DELETE FROM exitpoll_2022le.dbo.TMP_OUTPUT_PRE
|
DELETE FROM exitpoll.dbo.TMP_OUTPUT_PRE
|
||||||
WHERE cand_party = #{f_cand_party}
|
WHERE cand_party = #{f_cand_party}
|
||||||
<if test="f_local == 'CHOICE'">
|
<if test="f_local == 'CHOICE'">
|
||||||
AND area_cd = #{area_cd}
|
AND area_cd = #{area_cd}
|
||||||
</if>
|
</if>
|
||||||
|
|
||||||
-- @@@@@ 14. TMP_PRE_P5N_CNT을 사용하여 층 X 후보(정당) X 사전 조사 옵션 별 count를 계산하여 TMP_OUTPUT_PRE에 넣는다
|
-- @@@@@ 14. TMP_PRE_P5N_CNT을 사용하여 층 X 후보(정당) X 사전 조사 옵션 별 count를 계산하여 TMP_OUTPUT_PRE에 넣는다
|
||||||
INSERT INTO exitpoll_2022le.dbo.TMP_OUTPUT_PRE
|
INSERT INTO exitpoll.dbo.TMP_OUTPUT_PRE
|
||||||
-- 선거구 - 후보별 사전투표율 옵션 1~9
|
-- 선거구 - 후보별 사전투표율 옵션 1~9
|
||||||
/*
|
/*
|
||||||
01 전화조사 판별(선관위 성by연령 반영)_DCO
|
01 전화조사 판별(선관위 성by연령 반영)_DCO
|
||||||
@@ -549,7 +549,7 @@
|
|||||||
*/
|
*/
|
||||||
SELECT area_cd, cand_party, cand_party_cd, option_cd, vote_rate
|
SELECT area_cd, cand_party, cand_party_cd, option_cd, vote_rate
|
||||||
FROM (
|
FROM (
|
||||||
SELECT area_cd, cand_party, option_cd, cand_party_cd, vote_rate FROM exitpoll_2022le.dbo.F_PRE WHERE cand_party = #{f_cand_party} UNION ALL
|
SELECT area_cd, cand_party, option_cd, cand_party_cd, vote_rate FROM exitpoll.dbo.F_PRE WHERE cand_party = #{f_cand_party} UNION ALL
|
||||||
SELECT TPP.area_cd, cand_party, option_cd, TPP.cand_party_cd,
|
SELECT TPP.area_cd, cand_party, option_cd, TPP.cand_party_cd,
|
||||||
CASE SUM(pre_cnt) WHEN 0 THEN 0.0
|
CASE SUM(pre_cnt) WHEN 0 THEN 0.0
|
||||||
ELSE SUM(pre_cnt) / SUM(pre_sum) * 100 -- 해당 후보의 현재 사전투표율(%)
|
ELSE SUM(pre_cnt) / SUM(pre_sum) * 100 -- 해당 후보의 현재 사전투표율(%)
|
||||||
@@ -558,16 +558,16 @@
|
|||||||
ELSE -1 * SUM(pre_cnt) / (SUM(pre_sum) - TPC.sel_pre_cnt) * weight_rate
|
ELSE -1 * SUM(pre_cnt) / (SUM(pre_sum) - TPC.sel_pre_cnt) * weight_rate
|
||||||
END
|
END
|
||||||
END AS vote_rate
|
END AS vote_rate
|
||||||
FROM exitpoll_2022le.dbo.TMP_PRE_P5N_CNT TPP LEFT JOIN (
|
FROM exitpoll.dbo.TMP_PRE_P5N_CNT TPP LEFT JOIN (
|
||||||
SELECT FPC.area_cd, FPC.cand_party_cd, SUM(pre_cnt) AS sel_pre_cnt
|
SELECT FPC.area_cd, FPC.cand_party_cd, SUM(pre_cnt) AS sel_pre_cnt
|
||||||
FROM exitpoll_2022le.dbo.F_PRE_CAND FPC JOIN exitpoll_2022le.dbo.TMP_PRE_P5N_CNT TPPC
|
FROM exitpoll.dbo.F_PRE_CAND FPC JOIN exitpoll.dbo.TMP_PRE_P5N_CNT TPPC
|
||||||
ON FPC.area_cd = TPPC.area_cd AND FPC.cand_party = #{f_cand_party} AND FPC.cand_party_cd = TPPC.cand_party_cd
|
ON FPC.area_cd = TPPC.area_cd AND FPC.cand_party = #{f_cand_party} AND FPC.cand_party_cd = TPPC.cand_party_cd
|
||||||
GROUP BY FPC.area_cd, FPC.cand_party_cd
|
GROUP BY FPC.area_cd, FPC.cand_party_cd
|
||||||
) TPC
|
) TPC
|
||||||
ON TPP.area_cd = TPC.area_cd AND TPP.cand_party_cd != TPC.cand_party_cd LEFT JOIN
|
ON TPP.area_cd = TPC.area_cd AND TPP.cand_party_cd != TPC.cand_party_cd LEFT JOIN
|
||||||
(
|
(
|
||||||
SELECT weight_rate, option_cd
|
SELECT weight_rate, option_cd
|
||||||
FROM exitpoll_2022le.dbo.F_option
|
FROM exitpoll.dbo.F_option
|
||||||
WHERE vote_cd = '1'
|
WHERE vote_cd = '1'
|
||||||
and option_type = '2'
|
and option_type = '2'
|
||||||
--SELECT number + CASE WHEN number > 3 THEN number - 3 ELSE 0 END AS weight_rate, FORMAT(number+4, '00') AS option_cd
|
--SELECT number + CASE WHEN number > 3 THEN number - 3 ELSE 0 END AS weight_rate, FORMAT(number+4, '00') AS option_cd
|
||||||
@@ -582,7 +582,7 @@
|
|||||||
|
|
||||||
-- @@@@@ 16. F_output 초기화
|
-- @@@@@ 16. F_output 초기화
|
||||||
-- 최종 예측치
|
-- 최종 예측치
|
||||||
DELETE FROM exitpoll_2022le.dbo.F_output
|
DELETE FROM exitpoll.dbo.F_output
|
||||||
WHERE cand_party = #{f_cand_party}
|
WHERE cand_party = #{f_cand_party}
|
||||||
<if test="f_local == 'CHOICE'">
|
<if test="f_local == 'CHOICE'">
|
||||||
AND area_cd = #{area_cd}
|
AND area_cd = #{area_cd}
|
||||||
@@ -590,7 +590,7 @@
|
|||||||
|
|
||||||
-- @@@@@ 17. 층 X 후보(정당) X 옵션 별로 사전조사 득표율 * 사전조사 웨이팅, 당일조사 득표율 * 당일조사 웨이팅을 합하여 F_output에 넣는다
|
-- @@@@@ 17. 층 X 후보(정당) X 옵션 별로 사전조사 득표율 * 사전조사 웨이팅, 당일조사 득표율 * 당일조사 웨이팅을 합하여 F_output에 넣는다
|
||||||
-- poll_pre 사전 조사 웨이팅 , poll_5p 5시이전 웨이팅 , poll_5n 5시 이후 웨이팅(0)
|
-- poll_pre 사전 조사 웨이팅 , poll_5p 5시이전 웨이팅 , poll_5n 5시 이후 웨이팅(0)
|
||||||
INSERT INTO exitpoll_2022le.dbo.F_output
|
INSERT INTO exitpoll.dbo.F_output
|
||||||
SELECT DD.area_cd, DD.cand_party, PR.option_cd AS pre_option_cd, DD.option_cd, DD.cand_party_cd,
|
SELECT DD.area_cd, DD.cand_party, PR.option_cd AS pre_option_cd, DD.option_cd, DD.cand_party_cd,
|
||||||
ISNULL(SUM(
|
ISNULL(SUM(
|
||||||
W.cluster_weight * (
|
W.cluster_weight * (
|
||||||
@@ -610,18 +610,18 @@
|
|||||||
FROM
|
FROM
|
||||||
(
|
(
|
||||||
SELECT area_cd, cluster, cand_party, cand_party_cd, option_cd, CASE sum(cnt) WHEN 0 THEN 0.0 ELSE sum(cnt) / sum(sum_cnt) * 100 END AS vote_rate
|
SELECT area_cd, cluster, cand_party, cand_party_cd, option_cd, CASE sum(cnt) WHEN 0 THEN 0.0 ELSE sum(cnt) / sum(sum_cnt) * 100 END AS vote_rate
|
||||||
FROM exitpoll_2022le.dbo.TMP_OUTPUT_DDAY
|
FROM exitpoll.dbo.TMP_OUTPUT_DDAY
|
||||||
WHERE cand_party = #{f_cand_party}
|
WHERE cand_party = #{f_cand_party}
|
||||||
GROUP BY area_cd, cluster, cand_party, cand_party_cd, option_cd
|
GROUP BY area_cd, cluster, cand_party, cand_party_cd, option_cd
|
||||||
) DD LEFT JOIN exitpoll_2022le.dbo.TMP_OUTPUT_PRE PR
|
) DD LEFT JOIN exitpoll.dbo.TMP_OUTPUT_PRE PR
|
||||||
ON DD.area_cd = PR.area_cd AND DD.cand_party = PR.cand_party AND DD.cand_party_cd = PR.cand_party_cd LEFT JOIN
|
ON DD.area_cd = PR.area_cd AND DD.cand_party = PR.cand_party AND DD.cand_party_cd = PR.cand_party_cd LEFT JOIN
|
||||||
(
|
(
|
||||||
SELECT area_cd, cand_party, cand_party_cd,
|
SELECT area_cd, cand_party, cand_party_cd,
|
||||||
CASE SUM(p5n_cnt) WHEN 0 THEN 0.0 ELSE SUM(p5n_cnt) / SUM(p5n_sum) * 100 END AS vote_rate
|
CASE SUM(p5n_cnt) WHEN 0 THEN 0.0 ELSE SUM(p5n_cnt) / SUM(p5n_sum) * 100 END AS vote_rate
|
||||||
FROM exitpoll_2022le.dbo.TMP_PRE_P5N_CNT
|
FROM exitpoll.dbo.TMP_PRE_P5N_CNT
|
||||||
GROUP BY area_cd, cand_party, cand_party_cd
|
GROUP BY area_cd, cand_party, cand_party_cd
|
||||||
) PN ON DD.area_cd = PN.area_cd AND DD.cand_party = PN.cand_party AND DD.cand_party_cd = PN.cand_party_cd
|
) PN ON DD.area_cd = PN.area_cd AND DD.cand_party = PN.cand_party AND DD.cand_party_cd = PN.cand_party_cd
|
||||||
LEFT JOIN exitpoll_2022le.dbo.F_weight W ON DD.area_cd = W.area_cd AND DD.cluster = W.cluster
|
LEFT JOIN exitpoll.dbo.F_weight W ON DD.area_cd = W.area_cd AND DD.cluster = W.cluster
|
||||||
<if test="f_local == 'CHOICE'">
|
<if test="f_local == 'CHOICE'">
|
||||||
WHERE DD.area_cd = #{area_cd}
|
WHERE DD.area_cd = #{area_cd}
|
||||||
</if>
|
</if>
|
||||||
@@ -643,17 +643,17 @@
|
|||||||
from
|
from
|
||||||
(
|
(
|
||||||
SELECT area_cd, cluster, cand_party, cand_party_cd, option_cd, CASE sum(cnt) WHEN 0 THEN 0.0 ELSE sum(cnt) / sum(sum_cnt) * 100 END AS vote_rate
|
SELECT area_cd, cluster, cand_party, cand_party_cd, option_cd, CASE sum(cnt) WHEN 0 THEN 0.0 ELSE sum(cnt) / sum(sum_cnt) * 100 END AS vote_rate
|
||||||
FROM exitpoll_2022le.dbo.TMP_OUTPUT_DDAY
|
FROM exitpoll.dbo.TMP_OUTPUT_DDAY
|
||||||
WHERE cand_party = #{f_cand_party}
|
WHERE cand_party = #{f_cand_party}
|
||||||
GROUP BY area_cd, cluster, cand_party, cand_party_cd, option_cd
|
GROUP BY area_cd, cluster, cand_party, cand_party_cd, option_cd
|
||||||
) DD LEFT JOIN
|
) DD LEFT JOIN
|
||||||
(
|
(
|
||||||
SELECT area_cd, cand_party, cand_party_cd,
|
SELECT area_cd, cand_party, cand_party_cd,
|
||||||
CASE SUM(p5n_cnt) WHEN 0 THEN 0.0 ELSE SUM(p5n_cnt) / SUM(p5n_sum) * 100 END AS vote_rate
|
CASE SUM(p5n_cnt) WHEN 0 THEN 0.0 ELSE SUM(p5n_cnt) / SUM(p5n_sum) * 100 END AS vote_rate
|
||||||
FROM exitpoll_2022le.dbo.TMP_PRE_P5N_CNT
|
FROM exitpoll.dbo.TMP_PRE_P5N_CNT
|
||||||
GROUP BY area_cd, cand_party, cand_party_cd
|
GROUP BY area_cd, cand_party, cand_party_cd
|
||||||
) PN ON DD.area_cd = PN.area_cd AND DD.cand_party = PN.cand_party AND DD.cand_party_cd = PN.cand_party_cd
|
) PN ON DD.area_cd = PN.area_cd AND DD.cand_party = PN.cand_party AND DD.cand_party_cd = PN.cand_party_cd
|
||||||
LEFT JOIN exitpoll_2022le.dbo.F_weight W ON DD.area_cd = W.area_cd AND DD.cluster = W.cluster
|
LEFT JOIN exitpoll.dbo.F_weight W ON DD.area_cd = W.area_cd AND DD.cluster = W.cluster
|
||||||
<if test="f_local == 'CHOICE'">
|
<if test="f_local == 'CHOICE'">
|
||||||
WHERE DD.area_cd = #{area_cd}
|
WHERE DD.area_cd = #{area_cd}
|
||||||
</if>
|
</if>
|
||||||
@@ -662,21 +662,21 @@
|
|||||||
<if test="f_cand_party == 'CAND'">
|
<if test="f_cand_party == 'CAND'">
|
||||||
union all
|
union all
|
||||||
SELECT area_cd, 'CAND', option_cd, '00',cand_party_cd,vote_rate
|
SELECT area_cd, 'CAND', option_cd, '00',cand_party_cd,vote_rate
|
||||||
FROM exitpoll_2022le.dbo.TMP_OUTPUT_PRE
|
FROM exitpoll.dbo.TMP_OUTPUT_PRE
|
||||||
WHERE cand_party = 'CAND'
|
WHERE cand_party = 'CAND'
|
||||||
<if test="f_local == 'CHOICE'">
|
<if test="f_local == 'CHOICE'">
|
||||||
and area_cd = #{area_cd}
|
and area_cd = #{area_cd}
|
||||||
</if>
|
</if>
|
||||||
</if>
|
</if>
|
||||||
|
|
||||||
DELETE exitpoll_2022le.dbo.F_output_time WHERE cand_party = #{f_cand_party} and time_band = #{time_band}
|
DELETE exitpoll.dbo.F_output_time WHERE cand_party = #{f_cand_party} and time_band = #{time_band}
|
||||||
<if test="f_local == 'CHOICE'">
|
<if test="f_local == 'CHOICE'">
|
||||||
and area_cd = #{area_cd}
|
and area_cd = #{area_cd}
|
||||||
</if>
|
</if>
|
||||||
|
|
||||||
INSERT INTO exitpoll_2022le.dbo.F_output_time
|
INSERT INTO exitpoll.dbo.F_output_time
|
||||||
SELECT #{time_band} as time_band, area_cd, cand_party, pre_option_cd, option_cd, cand_party_cd,vote_rate
|
SELECT #{time_band} as time_band, area_cd, cand_party, pre_option_cd, option_cd, cand_party_cd,vote_rate
|
||||||
FROM exitpoll_2022le.dbo.F_output
|
FROM exitpoll.dbo.F_output
|
||||||
WHERE cand_party = #{f_cand_party}
|
WHERE cand_party = #{f_cand_party}
|
||||||
<if test="f_local == 'CHOICE'">
|
<if test="f_local == 'CHOICE'">
|
||||||
and area_cd = #{area_cd}
|
and area_cd = #{area_cd}
|
||||||
@@ -692,15 +692,15 @@
|
|||||||
<if test="f_cand_party == 'EDU'"> ISNULL(E.edu_nm, '무응답') AS cand_nm, </if>
|
<if test="f_cand_party == 'EDU'"> ISNULL(E.edu_nm, '무응답') AS cand_nm, </if>
|
||||||
ISNULL(P.party_nm, '무응답') AS party_nm, SUM(cnt) AS cnt
|
ISNULL(P.party_nm, '무응답') AS party_nm, SUM(cnt) AS cnt
|
||||||
FROM
|
FROM
|
||||||
exitpoll_2022le.dbo.TMP_EXIT_POLL TEP LEFT JOIN exitpoll_2022le.dbo.F_subarea SA
|
exitpoll.dbo.TMP_EXIT_POLL TEP LEFT JOIN exitpoll.dbo.F_subarea SA
|
||||||
ON TEP.area_cd = SA.area_cd AND TEP.subarea_cd = SA.subarea_cd
|
ON TEP.area_cd = SA.area_cd AND TEP.subarea_cd = SA.subarea_cd
|
||||||
<if test="f_cand_party == 'CAND'">
|
<if test="f_cand_party == 'CAND'">
|
||||||
LEFT JOIN exitpoll_2022le.dbo.F_cand C ON TEP.area_cd = C.area_cd AND TEP.cand_party_cd = C.cand_cd
|
LEFT JOIN exitpoll.dbo.F_cand C ON TEP.area_cd = C.area_cd AND TEP.cand_party_cd = C.cand_cd
|
||||||
</if>
|
</if>
|
||||||
<if test="f_cand_party == 'EDU'">
|
<if test="f_cand_party == 'EDU'">
|
||||||
LEFT JOIN exitpoll_2022le.dbo.F_Edu E ON TEP.area_cd = E.area_cd AND TEP.cand_party_cd = E.edu_cd AND E.quit = '0'
|
LEFT JOIN exitpoll.dbo.F_Edu E ON TEP.area_cd = E.area_cd AND TEP.cand_party_cd = E.edu_cd AND E.quit = '0'
|
||||||
</if>
|
</if>
|
||||||
LEFT JOIN exitpoll_2022le.dbo.F_party P ON
|
LEFT JOIN exitpoll.dbo.F_party P ON
|
||||||
<if test="f_cand_party == 'CAND'"> C.party_cd </if>
|
<if test="f_cand_party == 'CAND'"> C.party_cd </if>
|
||||||
<if test="f_cand_party == 'PARTY'"> TEP.cand_party_cd </if>
|
<if test="f_cand_party == 'PARTY'"> TEP.cand_party_cd </if>
|
||||||
<if test="f_cand_party == 'EDU'"> '99' </if>
|
<if test="f_cand_party == 'EDU'"> '99' </if>
|
||||||
@@ -725,7 +725,7 @@
|
|||||||
ELSE sect END as sect,
|
ELSE sect END as sect,
|
||||||
CASE cand_party_cd WHEN '00' THEN '999' ELSE cand_party_cd END as cand_party_cd,
|
CASE cand_party_cd WHEN '00' THEN '999' ELSE cand_party_cd END as cand_party_cd,
|
||||||
sum_cnt, cnt
|
sum_cnt, cnt
|
||||||
FROM exitpoll_2022le.dbo.TMP_CLUSTER_DATA
|
FROM exitpoll.dbo.TMP_CLUSTER_DATA
|
||||||
) T
|
) T
|
||||||
GROUP BY area_cd, cluster, cluster_nm, sect, cand_party_cd
|
GROUP BY area_cd, cluster, cluster_nm, sect, cand_party_cd
|
||||||
ORDER BY area_cd, cluster, sect, cand_party_cd
|
ORDER BY area_cd, cluster, sect, cand_party_cd
|
||||||
@@ -737,16 +737,16 @@
|
|||||||
(
|
(
|
||||||
SELECT area_cd, cand_party_cd, ROUND(CASE sum(cnt) WHEN 0 THEN 0.0 ELSE sum(cnt) / sum(sum_cnt) * 100 END, 1) AS p5p_rate,
|
SELECT area_cd, cand_party_cd, ROUND(CASE sum(cnt) WHEN 0 THEN 0.0 ELSE sum(cnt) / sum(sum_cnt) * 100 END, 1) AS p5p_rate,
|
||||||
ROUND(CASE SUM(p5n_cnt) WHEN 0 THEN 0.0 ELSE SUM(p5n_cnt) / SUM(p5n_sum) * 100 END, 1) AS p5n_rate
|
ROUND(CASE SUM(p5n_cnt) WHEN 0 THEN 0.0 ELSE SUM(p5n_cnt) / SUM(p5n_sum) * 100 END, 1) AS p5n_rate
|
||||||
FROM exitpoll_2022le.dbo.TMP_PRE_P5N_CNT
|
FROM exitpoll.dbo.TMP_PRE_P5N_CNT
|
||||||
GROUP BY area_cd, cand_party_cd
|
GROUP BY area_cd, cand_party_cd
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT area_cd, '999', ROUND(CASE sum(n_cnt) WHEN 0 THEN 0.0 ELSE sum(n_cnt) / sum(sum_cnt) * 100 END, 1), NULL
|
SELECT area_cd, '999', ROUND(CASE sum(n_cnt) WHEN 0 THEN 0.0 ELSE sum(n_cnt) / sum(sum_cnt) * 100 END, 1), NULL
|
||||||
FROM exitpoll_2022le.dbo.TMP_PRE_P5N_CNT
|
FROM exitpoll.dbo.TMP_PRE_P5N_CNT
|
||||||
GROUP BY area_cd
|
GROUP BY area_cd
|
||||||
) P5P LEFT JOIN (
|
) P5P LEFT JOIN (
|
||||||
SELECT area_cd, cand_party_cd,
|
SELECT area_cd, cand_party_cd,
|
||||||
JSON_QUERY('[' + STRING_AGG('{"option_cd":"' + option_cd + '","vote_rate":"' + FORMAT(ROUND(vote_rate, 1), '#0.0') + '"}', ',') + ']') AS pre_rate
|
JSON_QUERY('[' + STRING_AGG('{"option_cd":"' + option_cd + '","vote_rate":"' + FORMAT(ROUND(vote_rate, 1), '#0.0') + '"}', ',') + ']') AS pre_rate
|
||||||
FROM exitpoll_2022le.dbo.TMP_OUTPUT_PRE
|
FROM exitpoll.dbo.TMP_OUTPUT_PRE
|
||||||
WHERE cand_party = #{f_cand_party}
|
WHERE cand_party = #{f_cand_party}
|
||||||
GROUP BY area_cd, cand_party_cd
|
GROUP BY area_cd, cand_party_cd
|
||||||
) PRE ON P5P.area_cd = PRE.area_cd AND P5P.cand_party_cd = PRE.cand_party_cd
|
) PRE ON P5P.area_cd = PRE.area_cd AND P5P.cand_party_cd = PRE.cand_party_cd
|
||||||
@@ -758,13 +758,13 @@
|
|||||||
|
|
||||||
SELECT OP.area_cd, OP.cand_party, OP.option_cd, OP.cand_party_cd,
|
SELECT OP.area_cd, OP.cand_party, OP.option_cd, OP.cand_party_cd,
|
||||||
ROUND(vote_rate, 1) as vote_rate, CASE WHEN OO.area_cd IS NULL THEN '0' ELSE '1' END AS chk
|
ROUND(vote_rate, 1) as vote_rate, CASE WHEN OO.area_cd IS NULL THEN '0' ELSE '1' END AS chk
|
||||||
FROM exitpoll_2022le.dbo.F_output OP
|
FROM exitpoll.dbo.F_output OP
|
||||||
LEFT JOIN exitpoll_2022le.dbo.F_output_option OO
|
LEFT JOIN exitpoll.dbo.F_output_option OO
|
||||||
ON OP.area_cd = OO.area_cd AND OO.vote_cd = '2' AND OP.option_cd =
|
ON OP.area_cd = OO.area_cd AND OO.vote_cd = '2' AND OP.option_cd =
|
||||||
<if test="f_cand_party == 'CAND'"> OO.cand_option_cd </if>
|
<if test="f_cand_party == 'CAND'"> OO.cand_option_cd </if>
|
||||||
<if test="f_cand_party == 'PARTY'"> OO.party_option_cd </if>
|
<if test="f_cand_party == 'PARTY'"> OO.party_option_cd </if>
|
||||||
<if test="f_cand_party == 'EDU'"> OO.edu_option_cd </if>
|
<if test="f_cand_party == 'EDU'"> OO.edu_option_cd </if>
|
||||||
JOIN exitpoll_2022le.dbo.F_output_option POO
|
JOIN exitpoll.dbo.F_output_option POO
|
||||||
ON OP.area_cd = POO.area_cd AND POO.vote_cd = '1' AND OP.pre_option_cd =
|
ON OP.area_cd = POO.area_cd AND POO.vote_cd = '1' AND OP.pre_option_cd =
|
||||||
<if test="f_cand_party == 'CAND'"> POO.cand_option_cd </if>
|
<if test="f_cand_party == 'CAND'"> POO.cand_option_cd </if>
|
||||||
<if test="f_cand_party == 'PARTY'"> POO.party_option_cd </if>
|
<if test="f_cand_party == 'PARTY'"> POO.party_option_cd </if>
|
||||||
@@ -778,7 +778,7 @@
|
|||||||
FROM
|
FROM
|
||||||
(
|
(
|
||||||
SELECT DD.area_cd, DD.cand_party, DD.cand_party_cd, DD.option_cd, WE.cluster, WE.cluster_weight, CASE SUM(cnt) WHEN 0 THEN 0.0 ELSE SUM(cnt) / SUM(sum_cnt) * 100 END AS cls_rate
|
SELECT DD.area_cd, DD.cand_party, DD.cand_party_cd, DD.option_cd, WE.cluster, WE.cluster_weight, CASE SUM(cnt) WHEN 0 THEN 0.0 ELSE SUM(cnt) / SUM(sum_cnt) * 100 END AS cls_rate
|
||||||
FROM exitpoll_2022le.dbo.TMP_OUTPUT_DDAY DD LEFT JOIN exitpoll_2022le.dbo.F_Weight WE ON DD.area_cd = WE.area_cd AND DD.cluster = WE.cluster
|
FROM exitpoll.dbo.TMP_OUTPUT_DDAY DD LEFT JOIN exitpoll.dbo.F_Weight WE ON DD.area_cd = WE.area_cd AND DD.cluster = WE.cluster
|
||||||
WHERE DD.cand_party = #{f_cand_party}
|
WHERE DD.cand_party = #{f_cand_party}
|
||||||
GROUP BY DD.area_cd, DD.cand_party, DD.cand_party_cd, DD.option_cd, WE.cluster, WE.cluster_weight
|
GROUP BY DD.area_cd, DD.cand_party, DD.cand_party_cd, DD.option_cd, WE.cluster, WE.cluster_weight
|
||||||
) T
|
) T
|
||||||
@@ -794,12 +794,12 @@
|
|||||||
,OT.option_cd
|
,OT.option_cd
|
||||||
,OT.cand_party_cd
|
,OT.cand_party_cd
|
||||||
,OT.vote_rate
|
,OT.vote_rate
|
||||||
FROM exitpoll_2022le.dbo.F_output_time OT
|
FROM exitpoll.dbo.F_output_time OT
|
||||||
JOIN exitpoll_2022le.dbo.F_output_option OO ON OT.area_cd = OO.area_cd AND OO.vote_cd = '2' AND OT.option_cd =
|
JOIN exitpoll.dbo.F_output_option OO ON OT.area_cd = OO.area_cd AND OO.vote_cd = '2' AND OT.option_cd =
|
||||||
<if test="f_cand_party == 'CAND'"> OO.cand_option_cd </if>
|
<if test="f_cand_party == 'CAND'"> OO.cand_option_cd </if>
|
||||||
<if test="f_cand_party == 'PARTY'"> OO.party_option_cd </if>
|
<if test="f_cand_party == 'PARTY'"> OO.party_option_cd </if>
|
||||||
<if test="f_cand_party == 'EDU'"> OO.edu_option_cd </if>
|
<if test="f_cand_party == 'EDU'"> OO.edu_option_cd </if>
|
||||||
JOIN exitpoll_2022le.dbo.F_output_option POO ON OT.area_cd = POO.area_cd AND POO.vote_cd = '1' AND OT.pre_option_cd =
|
JOIN exitpoll.dbo.F_output_option POO ON OT.area_cd = POO.area_cd AND POO.vote_cd = '1' AND OT.pre_option_cd =
|
||||||
<if test="f_cand_party == 'CAND'"> POO.cand_option_cd </if>
|
<if test="f_cand_party == 'CAND'"> POO.cand_option_cd </if>
|
||||||
<if test="f_cand_party == 'PARTY'"> POO.party_option_cd </if>
|
<if test="f_cand_party == 'PARTY'"> POO.party_option_cd </if>
|
||||||
<if test="f_cand_party == 'EDU'"> POO.edu_option_cd </if>
|
<if test="f_cand_party == 'EDU'"> POO.edu_option_cd </if>
|
||||||
@@ -813,13 +813,13 @@
|
|||||||
<!-- 최종 선택된 옵션과 옵션 기준 득표율 (chk = '1' 선택, chk = '0' 미선택) -->
|
<!-- 최종 선택된 옵션과 옵션 기준 득표율 (chk = '1' 선택, chk = '0' 미선택) -->
|
||||||
SELECT OP.area_cd, OP.cand_party, OP.option_cd, OP.cand_party_cd,
|
SELECT OP.area_cd, OP.cand_party, OP.option_cd, OP.cand_party_cd,
|
||||||
ROUND(vote_rate, 1) as vote_rate, CASE WHEN OO.area_cd IS NULL THEN '0' ELSE '1' END AS chk
|
ROUND(vote_rate, 1) as vote_rate, CASE WHEN OO.area_cd IS NULL THEN '0' ELSE '1' END AS chk
|
||||||
FROM exitpoll_2022le.dbo.F_output OP
|
FROM exitpoll.dbo.F_output OP
|
||||||
LEFT JOIN exitpoll_2022le.dbo.F_output_option OO
|
LEFT JOIN exitpoll.dbo.F_output_option OO
|
||||||
ON OP.area_cd = OO.area_cd AND OO.vote_cd = '2' AND OP.option_cd =
|
ON OP.area_cd = OO.area_cd AND OO.vote_cd = '2' AND OP.option_cd =
|
||||||
<if test="f_cand_party == 'CAND'"> OO.cand_option_cd </if>
|
<if test="f_cand_party == 'CAND'"> OO.cand_option_cd </if>
|
||||||
<if test="f_cand_party == 'PARTY'"> OO.party_option_cd </if>
|
<if test="f_cand_party == 'PARTY'"> OO.party_option_cd </if>
|
||||||
<if test="f_cand_party == 'EDU'"> OO.edu_option_cd </if>
|
<if test="f_cand_party == 'EDU'"> OO.edu_option_cd </if>
|
||||||
JOIN exitpoll_2022le.dbo.F_output_option POO
|
JOIN exitpoll.dbo.F_output_option POO
|
||||||
ON OP.area_cd = POO.area_cd AND POO.vote_cd = '1' AND OP.pre_option_cd =
|
ON OP.area_cd = POO.area_cd AND POO.vote_cd = '1' AND OP.pre_option_cd =
|
||||||
<if test="f_cand_party == 'CAND'"> POO.cand_option_cd </if>
|
<if test="f_cand_party == 'CAND'"> POO.cand_option_cd </if>
|
||||||
<if test="f_cand_party == 'PARTY'"> POO.party_option_cd </if>
|
<if test="f_cand_party == 'PARTY'"> POO.party_option_cd </if>
|
||||||
@@ -838,12 +838,12 @@
|
|||||||
,OT.option_cd
|
,OT.option_cd
|
||||||
,OT.cand_party_cd
|
,OT.cand_party_cd
|
||||||
,OT.vote_rate
|
,OT.vote_rate
|
||||||
FROM exitpoll_2022le.dbo.F_output_time OT
|
FROM exitpoll.dbo.F_output_time OT
|
||||||
JOIN exitpoll_2022le.dbo.F_output_option OO ON OT.area_cd = OO.area_cd AND OO.vote_cd = '2' AND OT.option_cd =
|
JOIN exitpoll.dbo.F_output_option OO ON OT.area_cd = OO.area_cd AND OO.vote_cd = '2' AND OT.option_cd =
|
||||||
<if test="f_cand_party == 'CAND'"> OO.cand_option_cd </if>
|
<if test="f_cand_party == 'CAND'"> OO.cand_option_cd </if>
|
||||||
<if test="f_cand_party == 'PARTY'"> OO.party_option_cd </if>
|
<if test="f_cand_party == 'PARTY'"> OO.party_option_cd </if>
|
||||||
<if test="f_cand_party == 'EDU'"> OO.edu_option_cd </if>
|
<if test="f_cand_party == 'EDU'"> OO.edu_option_cd </if>
|
||||||
JOIN exitpoll_2022le.dbo.F_output_option POO ON OT.area_cd = POO.area_cd AND POO.vote_cd = '1' AND OT.pre_option_cd =
|
JOIN exitpoll.dbo.F_output_option POO ON OT.area_cd = POO.area_cd AND POO.vote_cd = '1' AND OT.pre_option_cd =
|
||||||
<if test="f_cand_party == 'CAND'"> POO.cand_option_cd </if>
|
<if test="f_cand_party == 'CAND'"> POO.cand_option_cd </if>
|
||||||
<if test="f_cand_party == 'PARTY'"> POO.party_option_cd </if>
|
<if test="f_cand_party == 'PARTY'"> POO.party_option_cd </if>
|
||||||
<if test="f_cand_party == 'EDU'"> POO.edu_option_cd </if>
|
<if test="f_cand_party == 'EDU'"> POO.edu_option_cd </if>
|
||||||
@@ -852,23 +852,23 @@
|
|||||||
<!-- 보고서 5 -->
|
<!-- 보고서 5 -->
|
||||||
</select>
|
</select>
|
||||||
<select id="getOutputFinalDataCnt" resultType="integer">
|
<select id="getOutputFinalDataCnt" resultType="integer">
|
||||||
SELECT count(*) as cnt FROM exitpoll_2022le.dbo.F_output_final
|
SELECT count(*) as cnt FROM exitpoll.dbo.F_output_final
|
||||||
WHERE CAND_PARTY = #{f_cand_party}
|
WHERE CAND_PARTY = #{f_cand_party}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
||||||
<insert id="putOutputFinalData">
|
<insert id="putOutputFinalData">
|
||||||
INSERT INTO exitpoll_2022le.dbo.F_output_final
|
INSERT INTO exitpoll.dbo.F_output_final
|
||||||
SELECT OP.area_cd, OP.cand_party, OP.pre_option_cd, OP.option_cd,
|
SELECT OP.area_cd, OP.cand_party, OP.pre_option_cd, OP.option_cd,
|
||||||
CASE OP.cand_party_cd WHEN '00' THEN '999' ELSE OP.cand_party_cd END as cand_party_cd,
|
CASE OP.cand_party_cd WHEN '00' THEN '999' ELSE OP.cand_party_cd END as cand_party_cd,
|
||||||
vote_rate
|
vote_rate
|
||||||
FROM exitpoll_2022le.dbo.F_output OP
|
FROM exitpoll.dbo.F_output OP
|
||||||
JOIN exitpoll_2022le.dbo.F_output_option OO
|
JOIN exitpoll.dbo.F_output_option OO
|
||||||
ON OP.area_cd = OO.area_cd AND OO.vote_cd = '2' AND OP.option_cd =
|
ON OP.area_cd = OO.area_cd AND OO.vote_cd = '2' AND OP.option_cd =
|
||||||
<if test="f_cand_party == 'CAND'"> OO.cand_option_cd </if>
|
<if test="f_cand_party == 'CAND'"> OO.cand_option_cd </if>
|
||||||
<if test="f_cand_party == 'PARTY'"> OO.party_option_cd </if>
|
<if test="f_cand_party == 'PARTY'"> OO.party_option_cd </if>
|
||||||
<if test="f_cand_party == 'EDU'"> OO.edu_option_cd </if>
|
<if test="f_cand_party == 'EDU'"> OO.edu_option_cd </if>
|
||||||
JOIN exitpoll_2022le.dbo.F_output_option POO
|
JOIN exitpoll.dbo.F_output_option POO
|
||||||
ON OP.area_cd = POO.area_cd AND POO.vote_cd = '1' AND OP.pre_option_cd =
|
ON OP.area_cd = POO.area_cd AND POO.vote_cd = '1' AND OP.pre_option_cd =
|
||||||
<if test="f_cand_party == 'CAND'"> POO.cand_option_cd </if>
|
<if test="f_cand_party == 'CAND'"> POO.cand_option_cd </if>
|
||||||
<if test="f_cand_party == 'PARTY'"> '00' </if> <!-- 비례정당은 사전 옵션 사용 X -->
|
<if test="f_cand_party == 'PARTY'"> '00' </if> <!-- 비례정당은 사전 옵션 사용 X -->
|
||||||
@@ -881,7 +881,7 @@
|
|||||||
<if test="f_cand_party == 'PARTY'">
|
<if test="f_cand_party == 'PARTY'">
|
||||||
SELECT B.*, A.PARTY_NM FROM
|
SELECT B.*, A.PARTY_NM FROM
|
||||||
(
|
(
|
||||||
SELECT PARTY_CD, PARTY_NM FROM exitpoll_2022le.dbo.F_PARTY WHERE PARTY_YN = '1'
|
SELECT PARTY_CD, PARTY_NM FROM exitpoll.dbo.F_PARTY WHERE PARTY_YN = '1'
|
||||||
) A
|
) A
|
||||||
LEFT JOIN
|
LEFT JOIN
|
||||||
(
|
(
|
||||||
@@ -894,14 +894,14 @@
|
|||||||
, O1.option_nm AS pre_option_nm
|
, O1.option_nm AS pre_option_nm
|
||||||
</if>
|
</if>
|
||||||
, OPF.option_cd, O2.option_nm, OPF.cand_party_cd, OPF.vote_rate
|
, OPF.option_cd, O2.option_nm, OPF.cand_party_cd, OPF.vote_rate
|
||||||
FROM exitpoll_2022le.dbo.F_output_final OPF
|
FROM exitpoll.dbo.F_output_final OPF
|
||||||
INNER JOIN exitpoll_2022le.dbo.F_area AR
|
INNER JOIN exitpoll.dbo.F_area AR
|
||||||
ON OPF.area_cd = AR.area_cd
|
ON OPF.area_cd = AR.area_cd
|
||||||
<if test="f_cand_party != 'PARTY'"> <!-- 비례정당은 사전 옵션 사용 X -->
|
<if test="f_cand_party != 'PARTY'"> <!-- 비례정당은 사전 옵션 사용 X -->
|
||||||
INNER JOIN exitpoll_2022le.dbo.F_option O1
|
INNER JOIN exitpoll.dbo.F_option O1
|
||||||
ON OPF.pre_option_cd = O1.option_cd AND O1.vote_cd = '1'
|
ON OPF.pre_option_cd = O1.option_cd AND O1.vote_cd = '1'
|
||||||
</if>
|
</if>
|
||||||
INNER JOIN exitpoll_2022le.dbo.F_option O2
|
INNER JOIN exitpoll.dbo.F_option O2
|
||||||
ON OPF.option_cd = O2.option_cd AND O2.vote_cd = '2'
|
ON OPF.option_cd = O2.option_cd AND O2.vote_cd = '2'
|
||||||
WHERE OPF.CAND_PARTY = #{f_cand_party}
|
WHERE OPF.CAND_PARTY = #{f_cand_party}
|
||||||
<if test="f_cand_party == 'PARTY'">
|
<if test="f_cand_party == 'PARTY'">
|
||||||
@@ -910,7 +910,7 @@
|
|||||||
</select>
|
</select>
|
||||||
|
|
||||||
<update id="editOutputFinalData">
|
<update id="editOutputFinalData">
|
||||||
UPDATE exitpoll_2022le.dbo.F_output_final
|
UPDATE exitpoll.dbo.F_output_final
|
||||||
SET vote_rate = #{vote_rate}
|
SET vote_rate = #{vote_rate}
|
||||||
WHERE AREA_CD = #{area_cd}
|
WHERE AREA_CD = #{area_cd}
|
||||||
AND cand_party = #{f_cand_party}
|
AND cand_party = #{f_cand_party}
|
||||||
@@ -918,7 +918,7 @@
|
|||||||
</update>
|
</update>
|
||||||
|
|
||||||
<delete id="dataInitialization">
|
<delete id="dataInitialization">
|
||||||
DELETE exitpoll_2022le.dbo.F_output_final
|
DELETE exitpoll.dbo.F_output_final
|
||||||
WHERE cand_party = #{f_cand_party}
|
WHERE cand_party = #{f_cand_party}
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
@@ -927,8 +927,8 @@
|
|||||||
<if test="f_cand_party == 'CAND'"> OO.cand_option_cd as final_option_cd </if>
|
<if test="f_cand_party == 'CAND'"> OO.cand_option_cd as final_option_cd </if>
|
||||||
<if test="f_cand_party == 'PARTY'"> OO.party_option_cd as final_option_cd </if>
|
<if test="f_cand_party == 'PARTY'"> OO.party_option_cd as final_option_cd </if>
|
||||||
<if test="f_cand_party == 'EDU'"> OO.edu_option_cd as final_option_cd </if>
|
<if test="f_cand_party == 'EDU'"> OO.edu_option_cd as final_option_cd </if>
|
||||||
FROM exitpoll_2022le.dbo.F_output_final OPF
|
FROM exitpoll.dbo.F_output_final OPF
|
||||||
INNER JOIN exitpoll_2022le.dbo.F_output_option OO
|
INNER JOIN exitpoll.dbo.F_output_option OO
|
||||||
ON OPF.area_cd = OO.area_cd
|
ON OPF.area_cd = OO.area_cd
|
||||||
WHERE OPF.cand_party = #{f_cand_party}
|
WHERE OPF.cand_party = #{f_cand_party}
|
||||||
GROUP BY OPF.AREA_CD, OO.vote_cd, OPF.pre_option_cd, OPF.option_cd,
|
GROUP BY OPF.AREA_CD, OO.vote_cd, OPF.pre_option_cd, OPF.option_cd,
|
||||||
@@ -938,7 +938,7 @@
|
|||||||
</select>
|
</select>
|
||||||
|
|
||||||
<update id="editOptionCommitFinalData">
|
<update id="editOptionCommitFinalData">
|
||||||
UPDATE exitpoll_2022le.dbo.F_output_final
|
UPDATE exitpoll.dbo.F_output_final
|
||||||
SET
|
SET
|
||||||
<if test="vote_cd == 1">
|
<if test="vote_cd == 1">
|
||||||
pre_option_cd = B.pre_option_cd,
|
pre_option_cd = B.pre_option_cd,
|
||||||
@@ -947,8 +947,8 @@
|
|||||||
option_cd = B.option_cd,
|
option_cd = B.option_cd,
|
||||||
</if>
|
</if>
|
||||||
vote_rate = B.vote_rate
|
vote_rate = B.vote_rate
|
||||||
FROM exitpoll_2022le.dbo.F_output_final A
|
FROM exitpoll.dbo.F_output_final A
|
||||||
LEFT JOIN exitpoll_2022le.dbo.F_output B
|
LEFT JOIN exitpoll.dbo.F_output B
|
||||||
ON A.area_cd = B.area_cd
|
ON A.area_cd = B.area_cd
|
||||||
AND A.cand_party = B.cand_party
|
AND A.cand_party = B.cand_party
|
||||||
AND A.cand_party_cd = B.cand_party_cd
|
AND A.cand_party_cd = B.cand_party_cd
|
||||||
@@ -963,7 +963,7 @@
|
|||||||
</update>
|
</update>
|
||||||
|
|
||||||
<update id="editOptionRollback">
|
<update id="editOptionRollback">
|
||||||
UPDATE exitpoll_2022le.dbo.F_output_option
|
UPDATE exitpoll.dbo.F_output_option
|
||||||
<if test="f_cand_party == 'CAND'"> SET cand_option_cd = #{option_cd} </if>
|
<if test="f_cand_party == 'CAND'"> SET cand_option_cd = #{option_cd} </if>
|
||||||
<if test="f_cand_party == 'PARTY'"> SET party_option_cd = #{option_cd} </if>
|
<if test="f_cand_party == 'PARTY'"> SET party_option_cd = #{option_cd} </if>
|
||||||
<if test="f_cand_party == 'EDU'"> SET edu_option_cd = #{option_cd} </if>
|
<if test="f_cand_party == 'EDU'"> SET edu_option_cd = #{option_cd} </if>
|
||||||
@@ -972,20 +972,20 @@
|
|||||||
</update>
|
</update>
|
||||||
|
|
||||||
<insert id="insertHtml">
|
<insert id="insertHtml">
|
||||||
INSERT INTO exitpoll_2022le.dbo.F_HTML(search_req, html_str, insert_user) VALUES (#{search_req}, #{html_str}, #{insert_user});
|
INSERT INTO exitpoll.dbo.F_HTML(search_req, html_str, insert_user) VALUES (#{search_req}, #{html_str}, #{insert_user});
|
||||||
</insert>
|
</insert>
|
||||||
<select id="historyDate" resultMap="AnalysisVo">
|
<select id="historyDate" resultMap="AnalysisVo">
|
||||||
SELECT id, search_req, CONVERT(varchar(19), insert_date, 120) as insert_date
|
SELECT id, search_req, CONVERT(varchar(19), insert_date, 120) as insert_date
|
||||||
FROM exitpoll_2022le.dbo.F_HTML
|
FROM exitpoll.dbo.F_HTML
|
||||||
WHERE flag = '1'
|
WHERE flag = '1'
|
||||||
ORDER BY insert_date DESC
|
ORDER BY insert_date DESC
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="historyHtml" resultMap="AnalysisVo">
|
<select id="historyHtml" resultMap="AnalysisVo">
|
||||||
SELECT html_str FROM exitpoll_2022le.dbo.F_HTML WHERE id = #{id}
|
SELECT html_str FROM exitpoll.dbo.F_HTML WHERE id = #{id}
|
||||||
</select>
|
</select>
|
||||||
<update id="deleteHistory">
|
<update id="deleteHistory">
|
||||||
UPDATE exitpoll_2022le.dbo.F_HTML
|
UPDATE exitpoll.dbo.F_HTML
|
||||||
SET flag = '0', update_date = getdate()
|
SET flag = '0', update_date = getdate()
|
||||||
WHERE id = #{id}
|
WHERE id = #{id}
|
||||||
</update>
|
</update>
|
||||||
|
|||||||
@@ -14,9 +14,9 @@
|
|||||||
FROM
|
FROM
|
||||||
(
|
(
|
||||||
SELECT area_cd, cluster, cand_party, sect, cand_party_cd, sum_cnt, cnt
|
SELECT area_cd, cluster, cand_party, sect, cand_party_cd, sum_cnt, cnt
|
||||||
FROM exitpoll_2022le.dbo.TMP_OUTPUT_DDAY
|
FROM exitpoll.dbo.TMP_OUTPUT_DDAY
|
||||||
WHERE option_cd = '07' and sect = '00'
|
WHERE option_cd = '07' and sect = '00'
|
||||||
) ST LEFT JOIN exitpoll_2022le.dbo.F_Weight W ON ST.area_cd = W.area_cd AND ST.cluster = W.cluster
|
) ST LEFT JOIN exitpoll.dbo.F_Weight W ON ST.area_cd = W.area_cd AND ST.cluster = W.cluster
|
||||||
GROUP BY ST.area_cd, cand_party, sect, cand_party_cd
|
GROUP BY ST.area_cd, cand_party, sect, cand_party_cd
|
||||||
) A LEFT JOIN (
|
) A LEFT JOIN (
|
||||||
SELECT area_cd, cand_party, cand_party_cd, vote_rate - CONVERT(NUMERIC(4,1), SUM(cls_rate * cluster_weight)) AS clas_rate, SUM(cls_rate * cluster_weight) AS dd_rate
|
SELECT area_cd, cand_party, cand_party_cd, vote_rate - CONVERT(NUMERIC(4,1), SUM(cls_rate * cluster_weight)) AS clas_rate, SUM(cls_rate * cluster_weight) AS dd_rate
|
||||||
@@ -24,9 +24,9 @@
|
|||||||
(
|
(
|
||||||
SELECT O.area_cd, O.cand_party, O.cand_party_cd, O.vote_rate, WE.cluster, WE.cluster_weight, case when ISNULL(SUM(sum_cnt), 0) = 0 then 0 else ISNULL(SUM(cnt), 0) / ISNULL(SUM(sum_cnt), 0) * 100 end
|
SELECT O.area_cd, O.cand_party, O.cand_party_cd, O.vote_rate, WE.cluster, WE.cluster_weight, case when ISNULL(SUM(sum_cnt), 0) = 0 then 0 else ISNULL(SUM(cnt), 0) / ISNULL(SUM(sum_cnt), 0) * 100 end
|
||||||
AS cls_rate
|
AS cls_rate
|
||||||
FROM exitpoll_2022le.dbo.F_output_final O LEFT JOIN exitpoll_2022le.dbo.TMP_OUTPUT_DDAY DD
|
FROM exitpoll.dbo.F_output_final O LEFT JOIN exitpoll.dbo.TMP_OUTPUT_DDAY DD
|
||||||
ON O.area_cd = DD.area_cd AND O.cand_party = DD.cand_party AND O.option_cd = DD.option_cd AND O.cand_party_cd = DD.cand_party_cd
|
ON O.area_cd = DD.area_cd AND O.cand_party = DD.cand_party AND O.option_cd = DD.option_cd AND O.cand_party_cd = DD.cand_party_cd
|
||||||
LEFT JOIN exitpoll_2022le.dbo.F_Weight WE ON DD.area_cd = WE.area_cd AND DD.cluster = WE.cluster
|
LEFT JOIN exitpoll.dbo.F_Weight WE ON DD.area_cd = WE.area_cd AND DD.cluster = WE.cluster
|
||||||
GROUP BY O.area_cd, O.cand_party, O.cand_party_cd, O.vote_rate, WE.cluster, WE.cluster_weight
|
GROUP BY O.area_cd, O.cand_party, O.cand_party_cd, O.vote_rate, WE.cluster, WE.cluster_weight
|
||||||
) SW
|
) SW
|
||||||
GROUP BY area_cd, cand_party, cand_party_cd, vote_rate
|
GROUP BY area_cd, cand_party, cand_party_cd, vote_rate
|
||||||
@@ -38,7 +38,7 @@
|
|||||||
-- vote_rate - 후보 득표율
|
-- vote_rate - 후보 득표율
|
||||||
-- cand_result - 후보 예측코드
|
-- cand_result - 후보 예측코드
|
||||||
select out_a.area_cd, out_a.area_cd_K, out_a.area_cd_M, out_a.area_cd_S
|
select out_a.area_cd, out_a.area_cd_K, out_a.area_cd_M, out_a.area_cd_S
|
||||||
, (select count(1) from exitpoll_2022le.dbo.f_cand c where c.area_cd=out_a.area_cd and c.quit = 0) as [cand_count]
|
, (select count(1) from exitpoll.dbo.f_cand c where c.area_cd=out_a.area_cd and c.quit = 0) as [cand_count]
|
||||||
, out_a.area_result, out_a.poll_cnt, out_a.err_limit, out_a.cand_party_cd
|
, out_a.area_result, out_a.poll_cnt, out_a.err_limit, out_a.cand_party_cd
|
||||||
, CASE WHEN out_c.quit = 0 THEN out_a.cand_result else 0 end as cand_result
|
, CASE WHEN out_c.quit = 0 THEN out_a.cand_result else 0 end as cand_result
|
||||||
, CASE WHEN out_c.quit = 0 THEN out_a.rnum else 0 end as rnum
|
, CASE WHEN out_c.quit = 0 THEN out_a.rnum else 0 end as rnum
|
||||||
@@ -58,11 +58,11 @@
|
|||||||
WHEN rank_1 - rank_2 <= PE.err_limit * 2 THEN
|
WHEN rank_1 - rank_2 <= PE.err_limit * 2 THEN
|
||||||
CASE WHEN ROW_NUMBER() OVER(PARTITION BY FOF.area_cd, FOF.cand_party ORDER BY CONVERT(NUMERIC(5,2), vote_rate) DESC) <= 2 THEN 2 ELSE 0 END
|
CASE WHEN ROW_NUMBER() OVER(PARTITION BY FOF.area_cd, FOF.cand_party ORDER BY CONVERT(NUMERIC(5,2), vote_rate) DESC) <= 2 THEN 2 ELSE 0 END
|
||||||
END AS cand_result
|
END AS cand_result
|
||||||
FROM exitpoll_2022le.dbo.F_output_final FOF LEFT JOIN exitpoll_2022le.dbo.F_area FA ON FOF.area_cd = FA.area_cd
|
FROM exitpoll.dbo.F_output_final FOF LEFT JOIN exitpoll.dbo.F_area FA ON FOF.area_cd = FA.area_cd
|
||||||
LEFT JOIN (
|
LEFT JOIN (
|
||||||
SELECT EP.area_cd, 'CAND' AS cand_party, count(C.area_cd) AS poll_cnt,
|
SELECT EP.area_cd, 'CAND' AS cand_party, count(C.area_cd) AS poll_cnt,
|
||||||
CASE WHEN ROUND(SQRT(2.5/count(C.area_cd)) * 100, 1) > 7.4 THEN 7.4 ELSE ROUND(SQRT(2.5/count(C.area_cd)) * 100, 1) END AS err_limit
|
CASE WHEN ROUND(SQRT(2.5/count(C.area_cd)) * 100, 1) > 7.4 THEN 7.4 ELSE ROUND(SQRT(2.5/count(C.area_cd)) * 100, 1) END AS err_limit
|
||||||
FROM exitpoll_2022le.dbo.F_TMP_EXPOLL EP LEFT JOIN exitpoll_2022le.dbo.F_Cand C ON EP.area_cd = C.area_cd AND EP.cand_cd = C.cand_cd
|
FROM exitpoll.dbo.F_TMP_EXPOLL EP LEFT JOIN exitpoll.dbo.F_Cand C ON EP.area_cd = C.area_cd AND EP.cand_cd = C.cand_cd
|
||||||
GROUP BY EP.area_cd
|
GROUP BY EP.area_cd
|
||||||
) PE ON FA.area_cd = PE.area_cd AND FOF.cand_party = PE.cand_party LEFT JOIN (
|
) PE ON FA.area_cd = PE.area_cd AND FOF.cand_party = PE.cand_party LEFT JOIN (
|
||||||
SELECT area_cd, cand_party,
|
SELECT area_cd, cand_party,
|
||||||
@@ -70,7 +70,7 @@
|
|||||||
FROM (
|
FROM (
|
||||||
SELECT ROW_NUMBER() OVER(PARTITION BY area_cd, cand_party ORDER BY CONVERT(NUMERIC(5,2), vote_rate) DESC) AS ran,
|
SELECT ROW_NUMBER() OVER(PARTITION BY area_cd, cand_party ORDER BY CONVERT(NUMERIC(5,2), vote_rate) DESC) AS ran,
|
||||||
area_cd, cand_party, CONVERT(NUMERIC(5,2), vote_rate) AS vote_rate
|
area_cd, cand_party, CONVERT(NUMERIC(5,2), vote_rate) AS vote_rate
|
||||||
FROM exitpoll_2022le.dbo.F_output_final
|
FROM exitpoll.dbo.F_output_final
|
||||||
) T
|
) T
|
||||||
PIVOT
|
PIVOT
|
||||||
(
|
(
|
||||||
@@ -96,12 +96,12 @@
|
|||||||
) SEC ON FOF.area_cd = SEC.area_cd AND FOF.cand_party = SEC.cand_party AND FOF.cand_party_cd = SEC.cand_party_cd LEFT JOIN
|
) SEC ON FOF.area_cd = SEC.area_cd AND FOF.cand_party = SEC.cand_party AND FOF.cand_party_cd = SEC.cand_party_cd LEFT JOIN
|
||||||
(
|
(
|
||||||
SELECT area_cd, cand_party, cand_party_cd, vote_rate AS pre_rate
|
SELECT area_cd, cand_party, cand_party_cd, vote_rate AS pre_rate
|
||||||
FROM exitpoll_2022le.dbo.TMP_OUTPUT_PRE A
|
FROM exitpoll.dbo.TMP_OUTPUT_PRE A
|
||||||
WHERE option_cd = (SELECT TOP 1 pre_option_cd FROM exitpoll_2022le.dbo.F_output_final WHERE area_cd = A.area_cd AND cand_party = A.cand_party)
|
WHERE option_cd = (SELECT TOP 1 pre_option_cd FROM exitpoll.dbo.F_output_final WHERE area_cd = A.area_cd AND cand_party = A.cand_party)
|
||||||
) PRE ON FOF.area_cd = PRE.area_cd AND FOF.cand_party = PRE.cand_party AND FOF.cand_party_cd = PRE.cand_party_cd
|
) PRE ON FOF.area_cd = PRE.area_cd AND FOF.cand_party = PRE.cand_party AND FOF.cand_party_cd = PRE.cand_party_cd
|
||||||
where FOF.cand_party = 'CAND'
|
where FOF.cand_party = 'CAND'
|
||||||
)out_a
|
)out_a
|
||||||
inner join exitpoll_2022le.dbo.f_cand out_c on out_a.area_cd = out_c.area_cd and out_a.cand_party_cd = out_c.cand_cd
|
inner join exitpoll.dbo.f_cand out_c on out_a.area_cd = out_c.area_cd and out_a.cand_party_cd = out_c.cand_cd
|
||||||
order by area_cd,cand_party_cd
|
order by area_cd,cand_party_cd
|
||||||
]]>
|
]]>
|
||||||
</select>
|
</select>
|
||||||
@@ -112,8 +112,8 @@
|
|||||||
, FOF.cand_party_cd
|
, FOF.cand_party_cd
|
||||||
, party_cd_K AS cand_party_cd_K, party_cd_M AS cand_party_cd_M, party_cd_S AS cand_party_cd_S
|
, party_cd_K AS cand_party_cd_K, party_cd_M AS cand_party_cd_M, party_cd_S AS cand_party_cd_S
|
||||||
, cast(vote_rate as float)/100 AS vote_rate, '2' as company_code
|
, cast(vote_rate as float)/100 AS vote_rate, '2' as company_code
|
||||||
FROM exitpoll_2022le.dbo.F_output_final FOF
|
FROM exitpoll.dbo.F_output_final FOF
|
||||||
inner join exitpoll_2022le.dbo.F_party FP on FOF.cand_party_cd=FP.party_cd
|
inner join exitpoll.dbo.F_party FP on FOF.cand_party_cd=FP.party_cd
|
||||||
where FOF.cand_party = 'PARTY'
|
where FOF.cand_party = 'PARTY'
|
||||||
ORDER BY FOF.area_cd, FOF.cand_party_cd
|
ORDER BY FOF.area_cd, FOF.cand_party_cd
|
||||||
</select>
|
</select>
|
||||||
@@ -130,10 +130,10 @@
|
|||||||
F.cand_party_cd,
|
F.cand_party_cd,
|
||||||
format(cast(F.vote_rate as float)/100,'0.000') as vote_rate,
|
format(cast(F.vote_rate as float)/100,'0.000') as vote_rate,
|
||||||
'2' as company_code
|
'2' as company_code
|
||||||
FROM exitpoll_2022le.dbo.F_output F
|
FROM exitpoll.dbo.F_output F
|
||||||
inner join exitpoll_2022le.dbo.F_output_option FO on F.area_cd=FO.area_cd and F.pre_option_cd=FO.cand_option_cd
|
inner join exitpoll.dbo.F_output_option FO on F.area_cd=FO.area_cd and F.pre_option_cd=FO.cand_option_cd
|
||||||
AND FO.vote_cd = '1'
|
AND FO.vote_cd = '1'
|
||||||
LEFT JOIN exitpoll_2022le.dbo.F_area A ON F.area_cd = A.area_cd
|
LEFT JOIN exitpoll.dbo.F_area A ON F.area_cd = A.area_cd
|
||||||
WHERE F.cand_party = 'CAND' AND F.option_cd='00'
|
WHERE F.cand_party = 'CAND' AND F.option_cd='00'
|
||||||
union all
|
union all
|
||||||
SELECT F.area_cd,
|
SELECT F.area_cd,
|
||||||
@@ -144,10 +144,10 @@
|
|||||||
F.cand_party_cd,
|
F.cand_party_cd,
|
||||||
format(cast(F.vote_rate as float)/100,'0.000') as vote_rate,
|
format(cast(F.vote_rate as float)/100,'0.000') as vote_rate,
|
||||||
'2' as company_code
|
'2' as company_code
|
||||||
FROM exitpoll_2022le.dbo.F_output F
|
FROM exitpoll.dbo.F_output F
|
||||||
inner join exitpoll_2022le.dbo.F_output_option FO on F.area_cd=FO.area_cd and F.option_cd=FO.cand_option_cd AND
|
inner join exitpoll.dbo.F_output_option FO on F.area_cd=FO.area_cd and F.option_cd=FO.cand_option_cd AND
|
||||||
FO.vote_cd = '2'
|
FO.vote_cd = '2'
|
||||||
LEFT JOIN exitpoll_2022le.dbo.F_area A ON F.area_cd = A.area_cd
|
LEFT JOIN exitpoll.dbo.F_area A ON F.area_cd = A.area_cd
|
||||||
WHERE F.cand_party = 'CAND' AND F.pre_option_cd='00'
|
WHERE F.cand_party = 'CAND' AND F.pre_option_cd='00'
|
||||||
) out_a
|
) out_a
|
||||||
<!-- where area_cd in ('0104','0116','0134','0147','0208','0211','0403','0408','0914','0930','0936','0945','0949','0959','1102','1108','1602','1605') -->
|
<!-- where area_cd in ('0104','0116','0134','0147','0208','0211','0403','0408','0914','0930','0936','0945','0949','0959','1102','1108','1602','1605') -->
|
||||||
@@ -166,62 +166,62 @@
|
|||||||
FROM
|
FROM
|
||||||
(
|
(
|
||||||
SELECT area_cd, cluster, cand_party, sect, cand_party_cd, sum_cnt, cnt
|
SELECT area_cd, cluster, cand_party, sect, cand_party_cd, sum_cnt, cnt
|
||||||
FROM exitpoll_2022le.dbo.TMP_OUTPUT_DDAY
|
FROM exitpoll.dbo.TMP_OUTPUT_DDAY
|
||||||
WHERE option_cd = '02'
|
WHERE option_cd = '02'
|
||||||
UNION ALL
|
UNION ALL
|
||||||
-- 남자/여자 60대 이상
|
-- 남자/여자 60대 이상
|
||||||
SELECT area_cd, cluster, cand_party, LEFT(sect, 1) + '7' AS sect, cand_party_cd, SUM(sum_cnt) AS sum_cnt, SUM(cnt) AS cnt
|
SELECT area_cd, cluster, cand_party, LEFT(sect, 1) + '7' AS sect, cand_party_cd, SUM(sum_cnt) AS sum_cnt, SUM(cnt) AS cnt
|
||||||
FROM exitpoll_2022le.dbo.TMP_OUTPUT_DDAY
|
FROM exitpoll.dbo.TMP_OUTPUT_DDAY
|
||||||
WHERE sect IN ('15','16','25','26') AND option_cd = '02'
|
WHERE sect IN ('15','16','25','26') AND option_cd = '02'
|
||||||
GROUP BY area_cd, cluster, cand_party, LEFT(sect, 1) + '7', cand_party_cd
|
GROUP BY area_cd, cluster, cand_party, LEFT(sect, 1) + '7', cand_party_cd
|
||||||
UNION ALL
|
UNION ALL
|
||||||
-- 남자/여자 40대50대
|
-- 남자/여자 40대50대
|
||||||
SELECT area_cd, cluster, cand_party, LEFT(sect, 1) + '8' AS sect, cand_party_cd, SUM(sum_cnt) AS sum_cnt, SUM(cnt) AS cnt
|
SELECT area_cd, cluster, cand_party, LEFT(sect, 1) + '8' AS sect, cand_party_cd, SUM(sum_cnt) AS sum_cnt, SUM(cnt) AS cnt
|
||||||
FROM exitpoll_2022le.dbo.TMP_OUTPUT_DDAY
|
FROM exitpoll.dbo.TMP_OUTPUT_DDAY
|
||||||
WHERE sect IN ('13','14','23','24') AND option_cd = '02'
|
WHERE sect IN ('13','14','23','24') AND option_cd = '02'
|
||||||
GROUP BY area_cd, cluster, cand_party, LEFT(sect, 1) + '8', cand_party_cd
|
GROUP BY area_cd, cluster, cand_party, LEFT(sect, 1) + '8', cand_party_cd
|
||||||
UNION ALL
|
UNION ALL
|
||||||
-- 남자/여자 30대이하
|
-- 남자/여자 30대이하
|
||||||
SELECT area_cd, cluster, cand_party, LEFT(sect, 1) + '9' AS sect, cand_party_cd, SUM(sum_cnt) AS sum_cnt, SUM(cnt) AS cnt
|
SELECT area_cd, cluster, cand_party, LEFT(sect, 1) + '9' AS sect, cand_party_cd, SUM(sum_cnt) AS sum_cnt, SUM(cnt) AS cnt
|
||||||
FROM exitpoll_2022le.dbo.TMP_OUTPUT_DDAY
|
FROM exitpoll.dbo.TMP_OUTPUT_DDAY
|
||||||
WHERE sect IN ('11','12','21','22') AND option_cd = '02'
|
WHERE sect IN ('11','12','21','22') AND option_cd = '02'
|
||||||
GROUP BY area_cd, cluster, cand_party, LEFT(sect, 1) + '9', cand_party_cd
|
GROUP BY area_cd, cluster, cand_party, LEFT(sect, 1) + '9', cand_party_cd
|
||||||
UNION ALL
|
UNION ALL
|
||||||
--남자/여자
|
--남자/여자
|
||||||
SELECT area_cd, cluster, cand_party, LEFT(sect, 1) + '0' AS sect, cand_party_cd, SUM(sum_cnt) AS sum_cnt, SUM(cnt) AS cnt
|
SELECT area_cd, cluster, cand_party, LEFT(sect, 1) + '0' AS sect, cand_party_cd, SUM(sum_cnt) AS sum_cnt, SUM(cnt) AS cnt
|
||||||
FROM exitpoll_2022le.dbo.TMP_OUTPUT_DDAY
|
FROM exitpoll.dbo.TMP_OUTPUT_DDAY
|
||||||
WHERE option_cd = '02'
|
WHERE option_cd = '02'
|
||||||
GROUP BY area_cd, cluster, cand_party, LEFT(sect, 1) + '0', cand_party_cd
|
GROUP BY area_cd, cluster, cand_party, LEFT(sect, 1) + '0', cand_party_cd
|
||||||
UNION ALL
|
UNION ALL
|
||||||
--20대/30대/40대/50대/60대/70대이상
|
--20대/30대/40대/50대/60대/70대이상
|
||||||
SELECT area_cd, cluster, cand_party, '0' + RIGHT(sect, 1) AS sect, cand_party_cd, SUM(sum_cnt) AS sum_cnt, SUM(cnt) AS cnt
|
SELECT area_cd, cluster, cand_party, '0' + RIGHT(sect, 1) AS sect, cand_party_cd, SUM(sum_cnt) AS sum_cnt, SUM(cnt) AS cnt
|
||||||
FROM exitpoll_2022le.dbo.TMP_OUTPUT_DDAY
|
FROM exitpoll.dbo.TMP_OUTPUT_DDAY
|
||||||
WHERE option_cd = '02'
|
WHERE option_cd = '02'
|
||||||
GROUP BY area_cd, cluster, cand_party, '0' + RIGHT(sect, 1), cand_party_cd
|
GROUP BY area_cd, cluster, cand_party, '0' + RIGHT(sect, 1), cand_party_cd
|
||||||
UNION ALL
|
UNION ALL
|
||||||
-- 60대이상
|
-- 60대이상
|
||||||
SELECT area_cd, cluster, cand_party, '07' AS sect, cand_party_cd, SUM(sum_cnt) AS sum_cnt, SUM(cnt) AS cnt
|
SELECT area_cd, cluster, cand_party, '07' AS sect, cand_party_cd, SUM(sum_cnt) AS sum_cnt, SUM(cnt) AS cnt
|
||||||
FROM exitpoll_2022le.dbo.TMP_OUTPUT_DDAY
|
FROM exitpoll.dbo.TMP_OUTPUT_DDAY
|
||||||
WHERE sect IN ('15','16','25','26') AND option_cd = '02'
|
WHERE sect IN ('15','16','25','26') AND option_cd = '02'
|
||||||
GROUP BY area_cd, cluster, cand_party, cand_party_cd
|
GROUP BY area_cd, cluster, cand_party, cand_party_cd
|
||||||
UNION ALL
|
UNION ALL
|
||||||
-- 40대50대(40세~59세)
|
-- 40대50대(40세~59세)
|
||||||
SELECT area_cd, cluster, cand_party, '08' AS sect, cand_party_cd, SUM(sum_cnt) AS sum_cnt, SUM(cnt) AS cnt
|
SELECT area_cd, cluster, cand_party, '08' AS sect, cand_party_cd, SUM(sum_cnt) AS sum_cnt, SUM(cnt) AS cnt
|
||||||
FROM exitpoll_2022le.dbo.TMP_OUTPUT_DDAY
|
FROM exitpoll.dbo.TMP_OUTPUT_DDAY
|
||||||
WHERE sect IN ('13','14','23','24') AND option_cd = '02'
|
WHERE sect IN ('13','14','23','24') AND option_cd = '02'
|
||||||
GROUP BY area_cd, cluster, cand_party, cand_party_cd
|
GROUP BY area_cd, cluster, cand_party, cand_party_cd
|
||||||
UNION ALL
|
UNION ALL
|
||||||
-- 30대이하(39세이하)
|
-- 30대이하(39세이하)
|
||||||
SELECT area_cd, cluster, cand_party, '09' AS sect, cand_party_cd, SUM(sum_cnt) AS sum_cnt, SUM(cnt) AS cnt
|
SELECT area_cd, cluster, cand_party, '09' AS sect, cand_party_cd, SUM(sum_cnt) AS sum_cnt, SUM(cnt) AS cnt
|
||||||
FROM exitpoll_2022le.dbo.TMP_OUTPUT_DDAY
|
FROM exitpoll.dbo.TMP_OUTPUT_DDAY
|
||||||
WHERE sect IN ('11','12','21','22') AND option_cd = '02'
|
WHERE sect IN ('11','12','21','22') AND option_cd = '02'
|
||||||
GROUP BY area_cd, cluster, cand_party, cand_party_cd
|
GROUP BY area_cd, cluster, cand_party, cand_party_cd
|
||||||
) ST LEFT JOIN exitpoll_2022le.dbo.F_Weight W ON ST.area_cd = W.area_cd AND ST.cluster = W.cluster
|
) ST LEFT JOIN exitpoll.dbo.F_Weight W ON ST.area_cd = W.area_cd AND ST.cluster = W.cluster
|
||||||
GROUP BY ST.area_cd, cand_party, sect, cand_party_cd
|
GROUP BY ST.area_cd, cand_party, sect, cand_party_cd
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT area_cd, cand_party, '9'+cluster, cand_party_cd, CONVERT(NUMERIC(4,1), case when ISNULL(SUM(sum_cnt), 0) = 0 then 0 else ISNULL(SUM(cnt), 0) / ISNULL(SUM(sum_cnt), 0) * 100 end
|
SELECT area_cd, cand_party, '9'+cluster, cand_party_cd, CONVERT(NUMERIC(4,1), case when ISNULL(SUM(sum_cnt), 0) = 0 then 0 else ISNULL(SUM(cnt), 0) / ISNULL(SUM(sum_cnt), 0) * 100 end
|
||||||
) AS sect_rate
|
) AS sect_rate
|
||||||
FROM exitpoll_2022le.dbo.TMP_OUTPUT_DDAY WHERE option_cd = '02'
|
FROM exitpoll.dbo.TMP_OUTPUT_DDAY WHERE option_cd = '02'
|
||||||
GROUP BY area_cd, cand_party, '9'+cluster, cand_party_cd
|
GROUP BY area_cd, cand_party, '9'+cluster, cand_party_cd
|
||||||
) A LEFT JOIN (
|
) A LEFT JOIN (
|
||||||
SELECT area_cd, cand_party, cand_party_cd, vote_rate - CONVERT(NUMERIC(4,1), SUM(cls_rate * cluster_weight)) AS clas_rate, SUM(cls_rate * cluster_weight) AS dd_rate
|
SELECT area_cd, cand_party, cand_party_cd, vote_rate - CONVERT(NUMERIC(4,1), SUM(cls_rate * cluster_weight)) AS clas_rate, SUM(cls_rate * cluster_weight) AS dd_rate
|
||||||
@@ -229,9 +229,9 @@
|
|||||||
(
|
(
|
||||||
SELECT O.area_cd, O.cand_party, O.cand_party_cd, O.vote_rate, WE.cluster, WE.cluster_weight, case when ISNULL(SUM(sum_cnt), 0) = 0 then 0 else ISNULL(SUM(cnt), 0) / ISNULL(SUM(sum_cnt), 0) * 100 end
|
SELECT O.area_cd, O.cand_party, O.cand_party_cd, O.vote_rate, WE.cluster, WE.cluster_weight, case when ISNULL(SUM(sum_cnt), 0) = 0 then 0 else ISNULL(SUM(cnt), 0) / ISNULL(SUM(sum_cnt), 0) * 100 end
|
||||||
AS cls_rate
|
AS cls_rate
|
||||||
FROM exitpoll_2022le.dbo.F_output_final O LEFT JOIN exitpoll_2022le.dbo.TMP_OUTPUT_DDAY DD
|
FROM exitpoll.dbo.F_output_final O LEFT JOIN exitpoll.dbo.TMP_OUTPUT_DDAY DD
|
||||||
ON O.area_cd = DD.area_cd AND O.cand_party = DD.cand_party AND O.option_cd = DD.option_cd AND O.cand_party_cd = DD.cand_party_cd
|
ON O.area_cd = DD.area_cd AND O.cand_party = DD.cand_party AND O.option_cd = DD.option_cd AND O.cand_party_cd = DD.cand_party_cd
|
||||||
LEFT JOIN exitpoll_2022le.dbo.F_Weight WE ON DD.area_cd = WE.area_cd AND DD.cluster = WE.cluster
|
LEFT JOIN exitpoll.dbo.F_Weight WE ON DD.area_cd = WE.area_cd AND DD.cluster = WE.cluster
|
||||||
GROUP BY O.area_cd, O.cand_party, O.cand_party_cd, O.vote_rate, WE.cluster, WE.cluster_weight
|
GROUP BY O.area_cd, O.cand_party, O.cand_party_cd, O.vote_rate, WE.cluster, WE.cluster_weight
|
||||||
) SW
|
) SW
|
||||||
GROUP BY area_cd, cand_party, cand_party_cd, vote_rate
|
GROUP BY area_cd, cand_party, cand_party_cd, vote_rate
|
||||||
@@ -261,15 +261,15 @@
|
|||||||
[91] as sect_91, [92] as sect_92, [93] as sect_93, [94] as sect_94, [95] as sect_95, [96] as sect_96, [97] as sect_97, [98] as sect_98,
|
[91] as sect_91, [92] as sect_92, [93] as sect_93, [94] as sect_94, [95] as sect_95, [96] as sect_96, [97] as sect_97, [98] as sect_98,
|
||||||
FORMAT(pre_rate, '00.0') AS pre_rate,
|
FORMAT(pre_rate, '00.0') AS pre_rate,
|
||||||
FORMAT(dd_rate, '00.0') AS dd_rate
|
FORMAT(dd_rate, '00.0') AS dd_rate
|
||||||
FROM exitpoll_2022le.dbo.F_output_final FOF LEFT JOIN exitpoll_2022le.dbo.F_area FA ON FOF.area_cd = FA.area_cd
|
FROM exitpoll.dbo.F_output_final FOF LEFT JOIN exitpoll.dbo.F_area FA ON FOF.area_cd = FA.area_cd
|
||||||
LEFT JOIN (
|
LEFT JOIN (
|
||||||
SELECT EP.area_cd, 'CAND' AS cand_party, count(C.area_cd) AS poll_cnt, ROUND(SQRT(2.5/count(C.area_cd)) * 100, 1) AS err_limit
|
SELECT EP.area_cd, 'CAND' AS cand_party, count(C.area_cd) AS poll_cnt, ROUND(SQRT(2.5/count(C.area_cd)) * 100, 1) AS err_limit
|
||||||
FROM exitpoll_2022le.dbo.F_TMP_EXPOLL EP LEFT JOIN exitpoll_2022le.dbo.F_Cand C ON EP.area_cd = C.area_cd AND EP.cand_cd = C.cand_cd AND C.quit = '0'
|
FROM exitpoll.dbo.F_TMP_EXPOLL EP LEFT JOIN exitpoll.dbo.F_Cand C ON EP.area_cd = C.area_cd AND EP.cand_cd = C.cand_cd AND C.quit = '0'
|
||||||
WHERE EP.area_cd != '0901'
|
WHERE EP.area_cd != '0901'
|
||||||
GROUP BY EP.area_cd
|
GROUP BY EP.area_cd
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT EP.area_cd, 'EDU' AS cand_party, count(E.area_cd) AS poll_cnt, ROUND(SQRT(2.5/count(E.area_cd)) * 100, 1) AS err_limit
|
SELECT EP.area_cd, 'EDU' AS cand_party, count(E.area_cd) AS poll_cnt, ROUND(SQRT(2.5/count(E.area_cd)) * 100, 1) AS err_limit
|
||||||
FROM exitpoll_2022le.dbo.F_TMP_EXPOLL EP LEFT JOIN exitpoll_2022le.dbo.F_edu E ON EP.area_cd = E.area_cd AND EP.edu_cd = E.edu_cd AND E.quit = '0'
|
FROM exitpoll.dbo.F_TMP_EXPOLL EP LEFT JOIN exitpoll.dbo.F_edu E ON EP.area_cd = E.area_cd AND EP.edu_cd = E.edu_cd AND E.quit = '0'
|
||||||
WHERE EP.area_cd != '0901'
|
WHERE EP.area_cd != '0901'
|
||||||
GROUP BY EP.area_cd
|
GROUP BY EP.area_cd
|
||||||
) PE ON FA.area_cd = PE.area_cd AND FOF.cand_party = PE.cand_party LEFT JOIN (
|
) PE ON FA.area_cd = PE.area_cd AND FOF.cand_party = PE.cand_party LEFT JOIN (
|
||||||
@@ -278,7 +278,7 @@
|
|||||||
FROM (
|
FROM (
|
||||||
SELECT ROW_NUMBER() OVER(PARTITION BY area_cd, cand_party ORDER BY CONVERT(NUMERIC(4,1), vote_rate) DESC) AS ran,
|
SELECT ROW_NUMBER() OVER(PARTITION BY area_cd, cand_party ORDER BY CONVERT(NUMERIC(4,1), vote_rate) DESC) AS ran,
|
||||||
area_cd, cand_party, CONVERT(NUMERIC(4,1), vote_rate) AS vote_rate
|
area_cd, cand_party, CONVERT(NUMERIC(4,1), vote_rate) AS vote_rate
|
||||||
FROM exitpoll_2022le.dbo.F_output_final
|
FROM exitpoll.dbo.F_output_final
|
||||||
WHERE area_cd != '0901'
|
WHERE area_cd != '0901'
|
||||||
) T
|
) T
|
||||||
PIVOT
|
PIVOT
|
||||||
@@ -326,8 +326,8 @@
|
|||||||
) SEC ON FOF.area_cd = SEC.area_cd AND FOF.cand_party = SEC.cand_party AND FOF.cand_party_cd = SEC.cand_party_cd LEFT JOIN
|
) SEC ON FOF.area_cd = SEC.area_cd AND FOF.cand_party = SEC.cand_party AND FOF.cand_party_cd = SEC.cand_party_cd LEFT JOIN
|
||||||
(
|
(
|
||||||
SELECT area_cd, cand_party, cand_party_cd, vote_rate AS pre_rate
|
SELECT area_cd, cand_party, cand_party_cd, vote_rate AS pre_rate
|
||||||
FROM exitpoll_2022le.dbo.TMP_OUTPUT_PRE A
|
FROM exitpoll.dbo.TMP_OUTPUT_PRE A
|
||||||
WHERE option_cd = (SELECT TOP 1 pre_option_cd FROM exitpoll_2022le.dbo.F_output_final WHERE area_cd = A.area_cd AND cand_party = A.cand_party)
|
WHERE option_cd = (SELECT TOP 1 pre_option_cd FROM exitpoll.dbo.F_output_final WHERE area_cd = A.area_cd AND cand_party = A.cand_party)
|
||||||
) PRE ON FOF.area_cd = PRE.area_cd AND FOF.cand_party = PRE.cand_party AND FOF.cand_party_cd = PRE.cand_party_cd
|
) PRE ON FOF.area_cd = PRE.area_cd AND FOF.cand_party = PRE.cand_party AND FOF.cand_party_cd = PRE.cand_party_cd
|
||||||
WHERE FOF.area_cd != '0901'
|
WHERE FOF.area_cd != '0901'
|
||||||
]]>
|
]]>
|
||||||
@@ -344,55 +344,55 @@
|
|||||||
FROM
|
FROM
|
||||||
(
|
(
|
||||||
SELECT area_cd, cluster, cand_party, sect, cand_party_cd, sum_cnt, cnt
|
SELECT area_cd, cluster, cand_party, sect, cand_party_cd, sum_cnt, cnt
|
||||||
FROM exitpoll_2022le.dbo.TMP_OUTPUT_DDAY
|
FROM exitpoll.dbo.TMP_OUTPUT_DDAY
|
||||||
WHERE option_cd = '02'
|
WHERE option_cd = '02'
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT area_cd, cluster, cand_party, LEFT(sect, 1) + '7' AS sect, cand_party_cd, SUM(sum_cnt) AS sum_cnt, SUM(cnt) AS cnt
|
SELECT area_cd, cluster, cand_party, LEFT(sect, 1) + '7' AS sect, cand_party_cd, SUM(sum_cnt) AS sum_cnt, SUM(cnt) AS cnt
|
||||||
FROM exitpoll_2022le.dbo.TMP_OUTPUT_DDAY
|
FROM exitpoll.dbo.TMP_OUTPUT_DDAY
|
||||||
WHERE sect IN ('15','16','25','26') AND option_cd = '02'
|
WHERE sect IN ('15','16','25','26') AND option_cd = '02'
|
||||||
GROUP BY area_cd, cluster, cand_party, LEFT(sect, 1) + '7', cand_party_cd
|
GROUP BY area_cd, cluster, cand_party, LEFT(sect, 1) + '7', cand_party_cd
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT area_cd, cluster, cand_party, LEFT(sect, 1) + '0' AS sect, cand_party_cd, SUM(sum_cnt) AS sum_cnt, SUM(cnt) AS cnt
|
SELECT area_cd, cluster, cand_party, LEFT(sect, 1) + '0' AS sect, cand_party_cd, SUM(sum_cnt) AS sum_cnt, SUM(cnt) AS cnt
|
||||||
FROM exitpoll_2022le.dbo.TMP_OUTPUT_DDAY
|
FROM exitpoll.dbo.TMP_OUTPUT_DDAY
|
||||||
WHERE option_cd = '02'
|
WHERE option_cd = '02'
|
||||||
GROUP BY area_cd, cluster, cand_party, LEFT(sect, 1) + '0', cand_party_cd
|
GROUP BY area_cd, cluster, cand_party, LEFT(sect, 1) + '0', cand_party_cd
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT area_cd, cluster, cand_party, '0' + RIGHT(sect, 1) AS sect, cand_party_cd, SUM(sum_cnt) AS sum_cnt, SUM(cnt) AS cnt
|
SELECT area_cd, cluster, cand_party, '0' + RIGHT(sect, 1) AS sect, cand_party_cd, SUM(sum_cnt) AS sum_cnt, SUM(cnt) AS cnt
|
||||||
FROM exitpoll_2022le.dbo.TMP_OUTPUT_DDAY
|
FROM exitpoll.dbo.TMP_OUTPUT_DDAY
|
||||||
WHERE option_cd = '02'
|
WHERE option_cd = '02'
|
||||||
GROUP BY area_cd, cluster, cand_party, '0' + RIGHT(sect, 1), cand_party_cd
|
GROUP BY area_cd, cluster, cand_party, '0' + RIGHT(sect, 1), cand_party_cd
|
||||||
UNION ALL
|
UNION ALL
|
||||||
-- 60대이상
|
-- 60대이상
|
||||||
SELECT area_cd, cluster, cand_party, '07' AS sect, cand_party_cd, SUM(sum_cnt) AS sum_cnt, SUM(cnt) AS cnt
|
SELECT area_cd, cluster, cand_party, '07' AS sect, cand_party_cd, SUM(sum_cnt) AS sum_cnt, SUM(cnt) AS cnt
|
||||||
FROM exitpoll_2022le.dbo.TMP_OUTPUT_DDAY
|
FROM exitpoll.dbo.TMP_OUTPUT_DDAY
|
||||||
WHERE sect IN ('15','16','25','26') AND option_cd = '02'
|
WHERE sect IN ('15','16','25','26') AND option_cd = '02'
|
||||||
GROUP BY area_cd, cluster, cand_party, cand_party_cd
|
GROUP BY area_cd, cluster, cand_party, cand_party_cd
|
||||||
UNION ALL
|
UNION ALL
|
||||||
-- 40대50대(40세~59세)
|
-- 40대50대(40세~59세)
|
||||||
SELECT area_cd, cluster, cand_party, '08' AS sect, cand_party_cd, SUM(sum_cnt) AS sum_cnt, SUM(cnt) AS cnt
|
SELECT area_cd, cluster, cand_party, '08' AS sect, cand_party_cd, SUM(sum_cnt) AS sum_cnt, SUM(cnt) AS cnt
|
||||||
FROM exitpoll_2022le.dbo.TMP_OUTPUT_DDAY
|
FROM exitpoll.dbo.TMP_OUTPUT_DDAY
|
||||||
WHERE sect IN ('13','14','23','24') AND option_cd = '02'
|
WHERE sect IN ('13','14','23','24') AND option_cd = '02'
|
||||||
GROUP BY area_cd, cluster, cand_party, cand_party_cd
|
GROUP BY area_cd, cluster, cand_party, cand_party_cd
|
||||||
UNION ALL
|
UNION ALL
|
||||||
-- 30대이하(39세이하)
|
-- 30대이하(39세이하)
|
||||||
SELECT area_cd, cluster, cand_party, '09' AS sect, cand_party_cd, SUM(sum_cnt) AS sum_cnt, SUM(cnt) AS cnt
|
SELECT area_cd, cluster, cand_party, '09' AS sect, cand_party_cd, SUM(sum_cnt) AS sum_cnt, SUM(cnt) AS cnt
|
||||||
FROM exitpoll_2022le.dbo.TMP_OUTPUT_DDAY
|
FROM exitpoll.dbo.TMP_OUTPUT_DDAY
|
||||||
WHERE sect IN ('11','12','21','22') AND option_cd = '02'
|
WHERE sect IN ('11','12','21','22') AND option_cd = '02'
|
||||||
GROUP BY area_cd, cluster, cand_party, cand_party_cd
|
GROUP BY area_cd, cluster, cand_party, cand_party_cd
|
||||||
) ST LEFT JOIN exitpoll_2022le.dbo.F_Weight W ON ST.area_cd = W.area_cd AND ST.cluster = W.cluster
|
) ST LEFT JOIN exitpoll.dbo.F_Weight W ON ST.area_cd = W.area_cd AND ST.cluster = W.cluster
|
||||||
GROUP BY ST.area_cd, cand_party, sect, cand_party_cd
|
GROUP BY ST.area_cd, cand_party, sect, cand_party_cd
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT area_cd, cand_party, '9'+cluster, cand_party_cd, CONVERT(NUMERIC(4,1), case when SUM(sum_cnt) = 0 then 0.0 else SUM(cnt) / SUM(sum_cnt) * 100 end) AS sect_rate
|
SELECT area_cd, cand_party, '9'+cluster, cand_party_cd, CONVERT(NUMERIC(4,1), case when SUM(sum_cnt) = 0 then 0.0 else SUM(cnt) / SUM(sum_cnt) * 100 end) AS sect_rate
|
||||||
FROM exitpoll_2022le.dbo.TMP_OUTPUT_DDAY WHERE option_cd = '02'
|
FROM exitpoll.dbo.TMP_OUTPUT_DDAY WHERE option_cd = '02'
|
||||||
GROUP BY area_cd, cand_party, '9'+cluster, cand_party_cd
|
GROUP BY area_cd, cand_party, '9'+cluster, cand_party_cd
|
||||||
) A LEFT JOIN (
|
) A LEFT JOIN (
|
||||||
SELECT area_cd, cand_party, cand_party_cd, vote_rate - CONVERT(NUMERIC(4,1), SUM(cls_rate * cluster_weight)) AS clas_rate, SUM(cls_rate * cluster_weight) AS dd_rate
|
SELECT area_cd, cand_party, cand_party_cd, vote_rate - CONVERT(NUMERIC(4,1), SUM(cls_rate * cluster_weight)) AS clas_rate, SUM(cls_rate * cluster_weight) AS dd_rate
|
||||||
FROM
|
FROM
|
||||||
(
|
(
|
||||||
SELECT O.area_cd, O.cand_party, O.cand_party_cd, O.vote_rate, WE.cluster, WE.cluster_weight, SUM(cnt) / SUM(sum_cnt) * 100 AS cls_rate
|
SELECT O.area_cd, O.cand_party, O.cand_party_cd, O.vote_rate, WE.cluster, WE.cluster_weight, SUM(cnt) / SUM(sum_cnt) * 100 AS cls_rate
|
||||||
FROM exitpoll_2022le.dbo.F_output_final O LEFT JOIN exitpoll_2022le.dbo.TMP_OUTPUT_DDAY DD
|
FROM exitpoll.dbo.F_output_final O LEFT JOIN exitpoll.dbo.TMP_OUTPUT_DDAY DD
|
||||||
ON O.area_cd = DD.area_cd AND O.cand_party = DD.cand_party AND O.option_cd = DD.option_cd AND O.cand_party_cd = DD.cand_party_cd
|
ON O.area_cd = DD.area_cd AND O.cand_party = DD.cand_party AND O.option_cd = DD.option_cd AND O.cand_party_cd = DD.cand_party_cd
|
||||||
LEFT JOIN exitpoll_2022le.dbo.F_Weight WE ON DD.area_cd = WE.area_cd AND DD.cluster = WE.cluster
|
LEFT JOIN exitpoll.dbo.F_Weight WE ON DD.area_cd = WE.area_cd AND DD.cluster = WE.cluster
|
||||||
GROUP BY O.area_cd, O.cand_party, O.cand_party_cd, O.vote_rate, WE.cluster, WE.cluster_weight
|
GROUP BY O.area_cd, O.cand_party, O.cand_party_cd, O.vote_rate, WE.cluster, WE.cluster_weight
|
||||||
) SW
|
) SW
|
||||||
GROUP BY area_cd, cand_party, cand_party_cd, vote_rate
|
GROUP BY area_cd, cand_party, cand_party_cd, vote_rate
|
||||||
@@ -419,10 +419,10 @@
|
|||||||
[10] as sect_10, [20] as sect_20, [01] as sect_01, [02] as sect_02, [03] as sect_03, [04] as sect_04, [07] as sect_07, [05] as sect_05, [06] as sect_06, [08] as sect_08, [09] as sect_09,
|
[10] as sect_10, [20] as sect_20, [01] as sect_01, [02] as sect_02, [03] as sect_03, [04] as sect_04, [07] as sect_07, [05] as sect_05, [06] as sect_06, [08] as sect_08, [09] as sect_09,
|
||||||
FORMAT(pre_rate, '00.0') AS pre_rate,
|
FORMAT(pre_rate, '00.0') AS pre_rate,
|
||||||
FORMAT(dd_rate, '00.0') AS dd_rate
|
FORMAT(dd_rate, '00.0') AS dd_rate
|
||||||
FROM exitpoll_2022le.dbo.F_output_final FOF LEFT JOIN exitpoll_2022le.dbo.F_area FA ON FOF.area_cd = FA.area_cd
|
FROM exitpoll.dbo.F_output_final FOF LEFT JOIN exitpoll.dbo.F_area FA ON FOF.area_cd = FA.area_cd
|
||||||
LEFT JOIN (
|
LEFT JOIN (
|
||||||
SELECT EP.area_cd, 'CAND' AS cand_party, count(C.area_cd) AS poll_cnt, ROUND(SQRT(2.5/count(C.area_cd)) * 100, 1) AS err_limit
|
SELECT EP.area_cd, 'CAND' AS cand_party, count(C.area_cd) AS poll_cnt, ROUND(SQRT(2.5/count(C.area_cd)) * 100, 1) AS err_limit
|
||||||
FROM exitpoll_2022le.dbo.F_TMP_EXPOLL EP LEFT JOIN exitpoll_2022le.dbo.F_Cand C ON EP.area_cd = C.area_cd AND EP.cand_cd = C.cand_cd AND C.quit = '0'
|
FROM exitpoll.dbo.F_TMP_EXPOLL EP LEFT JOIN exitpoll.dbo.F_Cand C ON EP.area_cd = C.area_cd AND EP.cand_cd = C.cand_cd AND C.quit = '0'
|
||||||
WHERE EP.area_cd = '0901'
|
WHERE EP.area_cd = '0901'
|
||||||
GROUP BY EP.area_cd
|
GROUP BY EP.area_cd
|
||||||
) PE ON FA.area_cd = PE.area_cd AND FOF.cand_party = PE.cand_party LEFT JOIN (
|
) PE ON FA.area_cd = PE.area_cd AND FOF.cand_party = PE.cand_party LEFT JOIN (
|
||||||
@@ -431,7 +431,7 @@
|
|||||||
FROM (
|
FROM (
|
||||||
SELECT ROW_NUMBER() OVER(PARTITION BY area_cd, cand_party ORDER BY CONVERT(NUMERIC(4,1), vote_rate) DESC) AS ran,
|
SELECT ROW_NUMBER() OVER(PARTITION BY area_cd, cand_party ORDER BY CONVERT(NUMERIC(4,1), vote_rate) DESC) AS ran,
|
||||||
area_cd, cand_party, CONVERT(NUMERIC(4,1), vote_rate) AS vote_rate
|
area_cd, cand_party, CONVERT(NUMERIC(4,1), vote_rate) AS vote_rate
|
||||||
FROM exitpoll_2022le.dbo.F_output_final
|
FROM exitpoll.dbo.F_output_final
|
||||||
WHERE area_cd = '0901'
|
WHERE area_cd = '0901'
|
||||||
) T
|
) T
|
||||||
PIVOT
|
PIVOT
|
||||||
@@ -479,8 +479,8 @@
|
|||||||
) SEC ON FOF.area_cd = SEC.area_cd AND FOF.cand_party = SEC.cand_party AND FOF.cand_party_cd = SEC.cand_party_cd LEFT JOIN
|
) SEC ON FOF.area_cd = SEC.area_cd AND FOF.cand_party = SEC.cand_party AND FOF.cand_party_cd = SEC.cand_party_cd LEFT JOIN
|
||||||
(
|
(
|
||||||
SELECT area_cd, cand_party, cand_party_cd, vote_rate AS pre_rate
|
SELECT area_cd, cand_party, cand_party_cd, vote_rate AS pre_rate
|
||||||
FROM exitpoll_2022le.dbo.TMP_OUTPUT_PRE A
|
FROM exitpoll.dbo.TMP_OUTPUT_PRE A
|
||||||
WHERE option_cd = (SELECT TOP 1 pre_option_cd FROM exitpoll_2022le.dbo.F_output_final WHERE area_cd = A.area_cd AND cand_party = A.cand_party)
|
WHERE option_cd = (SELECT TOP 1 pre_option_cd FROM exitpoll.dbo.F_output_final WHERE area_cd = A.area_cd AND cand_party = A.cand_party)
|
||||||
) PRE ON FOF.area_cd = PRE.area_cd AND FOF.cand_party = PRE.cand_party AND FOF.cand_party_cd = PRE.cand_party_cd
|
) PRE ON FOF.area_cd = PRE.area_cd AND FOF.cand_party = PRE.cand_party AND FOF.cand_party_cd = PRE.cand_party_cd
|
||||||
WHERE FOF.area_cd = '0901'
|
WHERE FOF.area_cd = '0901'
|
||||||
]]>
|
]]>
|
||||||
@@ -499,14 +499,14 @@
|
|||||||
FROM
|
FROM
|
||||||
(
|
(
|
||||||
SELECT A.area_cd, GA.gender, GA.age, SA.subarea_cd, CP.cand_party, CP.cand_party_cd
|
SELECT A.area_cd, GA.gender, GA.age, SA.subarea_cd, CP.cand_party, CP.cand_party_cd
|
||||||
FROM exitpoll_2022le.dbo.F_area A LEFT JOIN exitpoll_2022le.dbo.F_subarea SA
|
FROM exitpoll.dbo.F_area A LEFT JOIN exitpoll.dbo.F_subarea SA
|
||||||
ON A.area_cd = SA.area_cd LEFT JOIN (
|
ON A.area_cd = SA.area_cd LEFT JOIN (
|
||||||
SELECT 'CAND' AS cand_party, area_cd, cand_cd AS cand_party_cd
|
SELECT 'CAND' AS cand_party, area_cd, cand_cd AS cand_party_cd
|
||||||
FROM exitpoll_2022le.dbo.F_cand WHERE quit = '0' UNION ALL
|
FROM exitpoll.dbo.F_cand WHERE quit = '0' UNION ALL
|
||||||
SELECT 'PARTY' AS cand_party, '0000' AS area_cd, party_cd AS cand_party_cd
|
SELECT 'PARTY' AS cand_party, '0000' AS area_cd, party_cd AS cand_party_cd
|
||||||
FROM exitpoll_2022le.dbo.F_party WHERE party_yn = '1' UNION ALL
|
FROM exitpoll.dbo.F_party WHERE party_yn = '1' UNION ALL
|
||||||
SELECT 'EDU' AS cand_party, area_cd, edu_cd AS cand_party_cd
|
SELECT 'EDU' AS cand_party, area_cd, edu_cd AS cand_party_cd
|
||||||
FROM exitpoll_2022le.dbo.F_edu WHERE quit = '0' UNION ALL
|
FROM exitpoll.dbo.F_edu WHERE quit = '0' UNION ALL
|
||||||
SELECT 'CAND' AS cand_party, '0000' AS area_cd, '00' AS cand_party_cd UNION ALL
|
SELECT 'CAND' AS cand_party, '0000' AS area_cd, '00' AS cand_party_cd UNION ALL
|
||||||
SELECT 'PARTY' AS cand_party, '0000' AS area_cd, '00' AS cand_party_cd UNION ALL
|
SELECT 'PARTY' AS cand_party, '0000' AS area_cd, '00' AS cand_party_cd UNION ALL
|
||||||
SELECT 'EDU' AS cand_party, '0000' AS area_cd, '00' AS cand_party_cd
|
SELECT 'EDU' AS cand_party, '0000' AS area_cd, '00' AS cand_party_cd
|
||||||
@@ -525,7 +525,7 @@
|
|||||||
SELECT area_cd, subarea_cd, gender, age,
|
SELECT area_cd, subarea_cd, gender, age,
|
||||||
cand_cd
|
cand_cd
|
||||||
AS cand_party_cd, count(*) AS cnt
|
AS cand_party_cd, count(*) AS cnt
|
||||||
FROM exitpoll_2022le.dbo.F_TMP_EXPOLL
|
FROM exitpoll.dbo.F_TMP_EXPOLL
|
||||||
WHERE 1=1
|
WHERE 1=1
|
||||||
GROUP BY area_cd, subarea_cd, gender, age,
|
GROUP BY area_cd, subarea_cd, gender, age,
|
||||||
cand_cd
|
cand_cd
|
||||||
@@ -541,7 +541,7 @@
|
|||||||
FROM
|
FROM
|
||||||
(
|
(
|
||||||
SELECT TXP.area_cd, A.area_nm, gender + age AS sect, SUM(cnt) AS cnt
|
SELECT TXP.area_cd, A.area_nm, gender + age AS sect, SUM(cnt) AS cnt
|
||||||
FROM #TMP_EXIT_POLL TXP LEFT JOIN exitpoll_2022le.dbo.F_area A ON TXP.area_cd = A.area_cd
|
FROM #TMP_EXIT_POLL TXP LEFT JOIN exitpoll.dbo.F_area A ON TXP.area_cd = A.area_cd
|
||||||
WHERE TXP.area_cd != '0901' AND gender != '0' AND age != '0'
|
WHERE TXP.area_cd != '0901' AND gender != '0' AND age != '0'
|
||||||
GROUP BY TXP.area_cd, A.area_nm, gender, age
|
GROUP BY TXP.area_cd, A.area_nm, gender, age
|
||||||
) T
|
) T
|
||||||
@@ -561,8 +561,8 @@
|
|||||||
FROM
|
FROM
|
||||||
(
|
(
|
||||||
SELECT F.area_cd, A.area_nm, CASE WHEN party_cd IN ('01', '02', '03') THEN party_cd ELSE '99' END party_cd, FORMAT(SUM(CONVERT(NUMERIC(4,1), vote_rate)), '00.0') AS vote_rate
|
SELECT F.area_cd, A.area_nm, CASE WHEN party_cd IN ('01', '02', '03') THEN party_cd ELSE '99' END party_cd, FORMAT(SUM(CONVERT(NUMERIC(4,1), vote_rate)), '00.0') AS vote_rate
|
||||||
FROM exitpoll_2022le.dbo.F_output_final F LEFT JOIN exitpoll_2022le.dbo.F_area A ON F.area_cd = A.area_cd
|
FROM exitpoll.dbo.F_output_final F LEFT JOIN exitpoll.dbo.F_area A ON F.area_cd = A.area_cd
|
||||||
LEFT JOIN exitpoll_2022le.dbo.F_cand C ON F.area_cd = C.area_cd AND F.cand_party_cd = C.cand_cd
|
LEFT JOIN exitpoll.dbo.F_cand C ON F.area_cd = C.area_cd AND F.cand_party_cd = C.cand_cd
|
||||||
WHERE LEN(F.area_cd) = 2 AND F.cand_party = 'CAND'
|
WHERE LEN(F.area_cd) = 2 AND F.cand_party = 'CAND'
|
||||||
GROUP BY F.area_cd, A.area_nm, CASE WHEN party_cd IN ('01', '02', '03') THEN party_cd ELSE '99' END
|
GROUP BY F.area_cd, A.area_nm, CASE WHEN party_cd IN ('01', '02', '03') THEN party_cd ELSE '99' END
|
||||||
) T
|
) T
|
||||||
|
|||||||
Reference in New Issue
Block a user