-------------------------------------
-- 费控预算金额明细表建表
-------------------------------------
DROP TABLE IF EXISTS dw.dwd_cost_budget_data_d;
CREATE TABLE IF NOT EXISTS dw.dwd_cost_budget_data_d (
 dimaccountcode      VARCHAR(255) COMMENT '预算科目编码'
,dimaccountname      VARCHAR(255) COMMENT '预算科目名称'
,dimsubjectcode      VARCHAR(255) COMMENT '组织机构编码'
,dimsubjectname      VARCHAR(255) COMMENT '组织机构名称'
,yearname            VARCHAR(50) COMMENT '年'
,totalcode           VARCHAR(255) COMMENT '组织机构层级编码'
,monthname           VARCHAR(50) COMMENT '月'
,buget               VARCHAR(255) COMMENT '预算金额'
,occ                 VARCHAR(255) COMMENT '已占用金额'
,realfee             VARCHAR(255) COMMENT '已使用金额'
,available           VARCHAR(255) COMMENT '剩余可用金额'
,budgetfee_rate      VARCHAR(50) COMMENT '预算执行率'
)COMMENT = '费控预算金额明细表'

-- -----------------------------------
-- 费控预算金额明细表转换
-- -----------------------------------
INSERT INTO dw.dwd_cost_budget_data_d
select
dimaccountcode     -- 预算科目编码
,dimaccountname    -- 预算科目名称
,dimsubjectcode    -- 组织机构编码
,dimsubjectname    -- 组织机构名称
,yearname          -- 年
,totalcode         -- 组织机构层级编码
,'01'              AS monthname
,janbuget          AS buget         -- 预算金额    目标金额
,janocc            AS occ           -- 已占用金额   实际值？
,janreal           AS realfee       -- 已使用金额   差额
,janavailable      AS available     -- 剩余可用金额
,janbugetrate      AS budgetfee_rate-- 预算执行率
FROM dw.ods_cost_budget_data_d
WHERE dimaccountcode IN ('WY0401','WY040101','WY040102','WY040103','WY040104','WY040105','WY040106','WY040107','WY040108','WY040109','WY040110','WY040111','WY040112','WY040113','WY040114','WY0402','WY040201','WY040202','WY040203','WY040204','WY040205','WY040206','WY040207','WY040208','WY040209','WY040210','WY040211','WY040212','WY040213','WY040214','WY040215','WY040216')
UNION ALL
SELECT
dimaccountcode     -- 预算科目编码
,dimaccountname    -- 预算科目名称
,dimsubjectcode    -- 组织机构编码
,dimsubjectname    -- 组织机构名称
,yearname          -- 年
,totalcode         -- 组织机构层级编码
,'02'               AS monthname
,febbudget          AS buget         -- 预算金额
,febocc             AS occ           -- 已占用金额
,febreal            AS realfee       -- 已使用金额
,febavailable       AS available     -- 剩余可用金额
,febbudgetrate      AS budgetfee_rate-- 预算执行率
FROM dw.ods_cost_budget_data_d
WHERE dimaccountcode IN ('WY0401','WY040101','WY040102','WY040103','WY040104','WY040105','WY040106','WY040107','WY040108','WY040109','WY040110','WY040111','WY040112','WY040113','WY040114','WY0402','WY040201','WY040202','WY040203','WY040204','WY040205','WY040206','WY040207','WY040208','WY040209','WY040210','WY040211','WY040212','WY040213','WY040214','WY040215','WY040216')
UNION ALL
SELECT
dimaccountcode     -- 预算科目编码
,dimaccountname    -- 预算科目名称
,dimsubjectcode    -- 组织机构编码
,dimsubjectname    -- 组织机构名称
,yearname          -- 年
,totalcode         -- 组织机构层级编码
,'03'               AS monthname
,marbudget          AS buget         -- 预算金额
,marocc             AS occ           -- 已占用金额
,marreal            AS realfee       -- 已使用金额
,maravailable       AS available     -- 剩余可用金额
,marbudgetrate      AS budgetfee_rate-- 预算执行率
FROM dw.ods_cost_budget_data_d
WHERE dimaccountcode IN ('WY0401','WY040101','WY040102','WY040103','WY040104','WY040105','WY040106','WY040107','WY040108','WY040109','WY040110','WY040111','WY040112','WY040113','WY040114','WY0402','WY040201','WY040202','WY040203','WY040204','WY040205','WY040206','WY040207','WY040208','WY040209','WY040210','WY040211','WY040212','WY040213','WY040214','WY040215','WY040216')
UNION ALL
SELECT
dimaccountcode     -- 预算科目编码
,dimaccountname    -- 预算科目名称
,dimsubjectcode    -- 组织机构编码
,dimsubjectname    -- 组织机构名称
,yearname          -- 年
,totalcode         -- 组织机构层级编码
,'04'               AS monthname
,aprilbudget       AS buget         -- 预算金额
,aprilocc          AS occ           -- 已占用金额
,aprilreal         AS realfee       -- 已使用金额
,apravailable      AS available     -- 剩余可用金额
,aprilbudgetrate   AS budgetfee_rate-- 预算执行率
FROM dw.ods_cost_budget_data_d
WHERE dimaccountcode IN ('WY0401','WY040101','WY040102','WY040103','WY040104','WY040105','WY040106','WY040107','WY040108','WY040109','WY040110','WY040111','WY040112','WY040113','WY040114','WY0402','WY040201','WY040202','WY040203','WY040204','WY040205','WY040206','WY040207','WY040208','WY040209','WY040210','WY040211','WY040212','WY040213','WY040214','WY040215','WY040216')
UNION ALL
SELECT
dimaccountcode     -- 预算科目编码
,dimaccountname    -- 预算科目名称
,dimsubjectcode    -- 组织机构编码
,dimsubjectname    -- 组织机构名称
,yearname          -- 年
,totalcode         -- 组织机构层级编码
,'05'               AS monthname
,maybudget          AS buget         -- 预算金额
,mayocc             AS occ           -- 已占用金额
,mayreal            AS realfee       -- 已使用金额
,mayavailable       AS available     -- 剩余可用金额
,maybudgetrate      AS budgetfee_rate-- 预算执行率
FROM dw.ods_cost_budget_data_d
WHERE dimaccountcode IN ('WY0401','WY040101','WY040102','WY040103','WY040104','WY040105','WY040106','WY040107','WY040108','WY040109','WY040110','WY040111','WY040112','WY040113','WY040114','WY0402','WY040201','WY040202','WY040203','WY040204','WY040205','WY040206','WY040207','WY040208','WY040209','WY040210','WY040211','WY040212','WY040213','WY040214','WY040215','WY040216')
UNION ALL
SELECT
dimaccountcode     -- 预算科目编码
,dimaccountname    -- 预算科目名称
,dimsubjectcode    -- 组织机构编码
,dimsubjectname    -- 组织机构名称
,yearname          -- 年
,totalcode         -- 组织机构层级编码
,'06'               AS monthname
,junebudget        AS buget         -- 预算金额
,juneocc           AS occ           -- 已占用金额
,junereal          AS realfee       -- 已使用金额
,juneavailable     AS available     -- 剩余可用金额
,junebudgetrate    AS budgetfee_rate-- 预算执行率
FROM dw.ods_cost_budget_data_d
WHERE dimaccountcode IN ('WY0401','WY040101','WY040102','WY040103','WY040104','WY040105','WY040106','WY040107','WY040108','WY040109','WY040110','WY040111','WY040112','WY040113','WY040114','WY0402','WY040201','WY040202','WY040203','WY040204','WY040205','WY040206','WY040207','WY040208','WY040209','WY040210','WY040211','WY040212','WY040213','WY040214','WY040215','WY040216')
UNION ALL
SELECT
dimaccountcode     -- 预算科目编码
,dimaccountname    -- 预算科目名称
,dimsubjectcode    -- 组织机构编码
,dimsubjectname    -- 组织机构名称
,yearname          -- 年
,totalcode         -- 组织机构层级编码
,'07'               AS monthname
,julybudget         AS buget         -- 预算金额
,julyocc            AS occ           -- 已占用金额
,julyreal           AS realfee       -- 已使用金额
,julyavailable      AS available     -- 剩余可用金额
,julybudgetrate     AS budgetfee_rate-- 预算执行率
FROM dw.ods_cost_budget_data_d
WHERE dimaccountcode IN ('WY0401','WY040101','WY040102','WY040103','WY040104','WY040105','WY040106','WY040107','WY040108','WY040109','WY040110','WY040111','WY040112','WY040113','WY040114','WY0402','WY040201','WY040202','WY040203','WY040204','WY040205','WY040206','WY040207','WY040208','WY040209','WY040210','WY040211','WY040212','WY040213','WY040214','WY040215','WY040216')
UNION ALL
SELECT
dimaccountcode     -- 预算科目编码
,dimaccountname    -- 预算科目名称
,dimsubjectcode    -- 组织机构编码
,dimsubjectname    -- 组织机构名称
,yearname          -- 年
,totalcode         -- 组织机构层级编码
,'08'               AS monthname
,augbudget          AS buget         -- 预算金额
,augocc             AS occ           -- 已占用金额
,augreal            AS realfee       -- 已使用金额
,augavailable       AS available     -- 剩余可用金额
,augbudgetrate      AS budgetfee_rate-- 预算执行率
FROM dw.ods_cost_budget_data_d
WHERE dimaccountcode IN ('WY0401','WY040101','WY040102','WY040103','WY040104','WY040105','WY040106','WY040107','WY040108','WY040109','WY040110','WY040111','WY040112','WY040113','WY040114','WY0402','WY040201','WY040202','WY040203','WY040204','WY040205','WY040206','WY040207','WY040208','WY040209','WY040210','WY040211','WY040212','WY040213','WY040214','WY040215','WY040216')
UNION ALL
SELECT
dimaccountcode     -- 预算科目编码
,dimaccountname    -- 预算科目名称
,dimsubjectcode    -- 组织机构编码
,dimsubjectname    -- 组织机构名称
,yearname          -- 年
,totalcode         -- 组织机构层级编码
,'09'               AS monthname

,sepbudget          AS buget         -- 预算金额
,sepocc             AS occ           -- 已占用金额
,sepreal            AS realfee       -- 已使用金额
,sepavailable       AS available     -- 剩余可用金额
,sepbudgetrate      AS budgetfee_rate-- 预算执行率
FROM dw.ods_cost_budget_data_d
WHERE dimaccountcode IN ('WY0401','WY040101','WY040102','WY040103','WY040104','WY040105','WY040106','WY040107','WY040108','WY040109','WY040110','WY040111','WY040112','WY040113','WY040114','WY0402','WY040201','WY040202','WY040203','WY040204','WY040205','WY040206','WY040207','WY040208','WY040209','WY040210','WY040211','WY040212','WY040213','WY040214','WY040215','WY040216')
UNION ALL
SELECT
dimaccountcode     -- 预算科目编码
,dimaccountname    -- 预算科目名称
,dimsubjectcode    -- 组织机构编码
,dimsubjectname    -- 组织机构名称
,yearname          -- 年
,totalcode         -- 组织机构层级编码
,'10'               AS monthname
,octbudget          AS buget         -- 预算金额
,octocc             AS occ           -- 已占用金额
,octreal            AS realfee       -- 已使用金额
, octavailable      AS available     -- 剩余可用金额
,octbudgetrate      AS budgetfee_rate-- 预算执行率
FROM dw.ods_cost_budget_data_d
WHERE dimaccountcode IN ('WY0401','WY040101','WY040102','WY040103','WY040104','WY040105','WY040106','WY040107','WY040108','WY040109','WY040110','WY040111','WY040112','WY040113','WY040114','WY0402','WY040201','WY040202','WY040203','WY040204','WY040205','WY040206','WY040207','WY040208','WY040209','WY040210','WY040211','WY040212','WY040213','WY040214','WY040215','WY040216')
UNION ALL
SELECT
dimaccountcode     -- 预算科目编码
,dimaccountname    -- 预算科目名称
,dimsubjectcode    -- 组织机构编码
,dimsubjectname    -- 组织机构名称
,yearname          -- 年
,totalcode         -- 组织机构层级编码
,'11'               AS monthname
,novbudget          AS buget         -- 预算金额
,novocc             AS occ           -- 已占用金额
,novreal            AS realfee       -- 已使用金额
,novavailable       AS available     -- 剩余可用金额
,novbudgetrate      AS budgetfee_rate-- 预算执行率
FROM dw.ods_cost_budget_data_d
WHERE dimaccountcode IN ('WY0401','WY040101','WY040102','WY040103','WY040104','WY040105','WY040106','WY040107','WY040108','WY040109','WY040110','WY040111','WY040112','WY040113','WY040114','WY0402','WY040201','WY040202','WY040203','WY040204','WY040205','WY040206','WY040207','WY040208','WY040209','WY040210','WY040211','WY040212','WY040213','WY040214','WY040215','WY040216')
UNION ALL
SELECT
dimaccountcode     -- 预算科目编码
,dimaccountname    -- 预算科目名称
,dimsubjectcode    -- 组织机构编码
,dimsubjectname    -- 组织机构名称
,yearname          -- 年
,totalcode         -- 组织机构层级编码
,'12'               AS monthname
,decbudget          AS buget         -- 预算金额
,decocc             AS occ           -- 已占用金额
,decreal            AS realfee       -- 已使用金额
,decavailable       AS available     -- 剩余可用金额
,decbudgetrate      AS budgetfee_rate-- 预算执行率
FROM dw.ods_cost_budget_data_d
WHERE dimaccountcode IN ('WY0401','WY040101','WY040102','WY040103','WY040104','WY040105','WY040106','WY040107','WY040108','WY040109','WY040110','WY040111','WY040112','WY040113','WY040114','WY0402','WY040201','WY040202','WY040203','WY040204','WY040205','WY040206','WY040207','WY040208','WY040209','WY040210','WY040211','WY040212','WY040213','WY040214','WY040215','WY040216')
;