参数名称优化+日期筛选优化+数据更新事件

This commit is contained in:
yangkunan 2024-11-16 23:40:25 +08:00
parent e7f0060125
commit da3348d85a
12 changed files with 652 additions and 227 deletions

View File

@ -0,0 +1,211 @@
WITH corp AS (
SELECT
corp_code,
corp_name
FROM
"dwr"."dim_corp"
WHERE
corp_type = '实体'
AND (parent_corp_code LIKE '02%' OR corp_code = '0301')
${IF(LEN(sCorp )!=0," AND corp_code IN ('"+ sCorp +"')", "")}
),
base_info AS (
SELECT
LEFT(t1.subject_code,6) AS subject_code,
SUM(t1.begin_debit_blc) AS "期初借方余额",
SUM(t1.begin_credit_blc) AS "期初贷方余额",
SUM(t1.credit_amt) AS "贷方发生额",
SUM(t1.debit_amt) AS "借方发生额",
SUM(IF(t1.acnt_mon = '${FORMAT(sStart_mon,"MM")}',t1.begin_debit_blc,0)) AS "期初借方余额_本月",
SUM(IF(t1.acnt_mon = '${FORMAT(sStart_mon,"MM")}',t1.begin_credit_blc,0)) AS "期初贷方余额_本月",
SUM(IF(t1.acnt_mon = '${FORMAT(sStart_mon,"MM")}',t1.credit_amt,0)) AS "贷方发生额_本月",
SUM(IF(t1.acnt_mon = '${FORMAT(sStart_mon,"MM")}',t1.debit_amt,0)) AS "借方发生额_本月"
FROM
"dwr"."fact_fim_subject_balance" t1
JOIN corp t2 ON t1.corp_code = t2.corp_code
WHERE
t1.acnt_year = '${YEAR(sStart_mon)}'
AND t1.acnt_mon <= '${FORMAT(sStart_mon,"MM")}'
AND t1.subject_code LIKE '2221%'
GROUP BY
LEFT(subject_code,6)
),
subject_result AS (
SELECT
t1.subject_code AS "科目编号",
ABS(SUM("贷方发生额")) AS "应交",
ABS(SUM("贷方发生额_本月")) AS "应交_本月"
FROM
base_info t1
WHERE
t1.subject_code IN ('222102','222105','222104','222113','222114','222106','222107','222110','222108','222109','222112','222118','222125','222121')
GROUP BY
t1.subject_code
UNION ALL
SELECT
'其他税' AS "科目编号",
ABS(SUM(t1."贷方发生额") - SUM(IF(t1.subject_code IN ('222101','222102','222104','222105','222106','222107','222108','222109','222110','222112','222113','222114','222116','2221121','222123','222125'),t1."贷方发生额",0))) AS "应交",
ABS(SUM(t1."贷方发生额_本月") - SUM(IF(t1.subject_code IN ('222101','222102','222104','222105','222106','222107','222108','222109','222110','222112','222113','222114','222116','222121','222123','222125'),t1."贷方发生额_本月",0))) AS "应交_本月"
FROM
base_info t1
UNION ALL
SELECT
'增值税' AS "科目编号",
ABS(SUM(IF(LEFT(t1.subject_code,8) IN ('22210105','22210116','22210117'),t1.credit_amt,0)) + SUM(IF(LEFT(t1.subject_code,6) IN ('222123'),t1.credit_amt,0)) - SUM(IF(LEFT(t1.subject_code,8) IN ('22210101','22210104','22210108','22210110','22210112','22210118'),t1.credit_amt,0))) AS "应交",
ABS(SUM(IF(LEFT(t1.subject_code,8) IN ('22210105','22210116','22210117','222123') AND t1.acnt_mon = '${FORMAT(sStart_mon,"MM")}',t1.credit_amt,0)) + SUM(IF(LEFT(t1.subject_code,6) IN ('222123') AND t1.acnt_mon = '${FORMAT(sStart_mon,"MM")}',t1.credit_amt,0)) - SUM(IF(LEFT(t1.subject_code,8) IN ('22210101','22210104','22210108','22210110','22210112','22210118') AND t1.acnt_mon = '${FORMAT(sStart_mon,"MM")}',t1.debit_amt,0))) AS "应交_本月"
FROM
"dwr"."fact_fim_subject_balance" t1
JOIN corp t2 ON t1.corp_code = t2.corp_code
WHERE
t1.acnt_year = '${YEAR(sStart_mon)}'
AND t1.acnt_mon <= '${FORMAT(sStart_mon,"MM")}'
AND t1.subject_code LIKE '2221%'
UNION ALL
SELECT
'营业收入' AS "科目编号",
SUM(t1.credit_amt) AS "应交",
SUM(IF(t1.acnt_mon = '${FORMAT(sStart_mon,"MM")}',t1.credit_amt,0)) AS "应交_本月"
FROM
"dwr"."fact_fim_subject_balance" t1
JOIN corp t2 ON t1.corp_code = t2.corp_code
WHERE
t1.acnt_year = '${YEAR(sStart_mon)}'
AND t1.acnt_mon <= '${FORMAT(sStart_mon,"MM")}'
AND LEFT(t1.subject_code,4) IN ('6001','6051')
),
-- 同期
base_info_tq AS (
SELECT
LEFT(t1.subject_code,6) AS subject_code,
SUM(t1.begin_debit_blc) AS "期初借方余额",
SUM(t1.begin_credit_blc) AS "期初贷方余额",
SUM(t1.credit_amt) AS "贷方发生额",
SUM(t1.debit_amt) AS "借方发生额",
SUM(IF(t1.acnt_mon = '${FORMAT(sStart_mon,"MM")}',t1.begin_debit_blc,0)) AS "期初借方余额_本月",
SUM(IF(t1.acnt_mon = '${FORMAT(sStart_mon,"MM")}',t1.begin_credit_blc,0)) AS "期初贷方余额_本月",
SUM(IF(t1.acnt_mon = '${FORMAT(sStart_mon,"MM")}',t1.credit_amt,0)) AS "贷方发生额_本月",
SUM(IF(t1.acnt_mon = '${FORMAT(sStart_mon,"MM")}',t1.debit_amt,0)) AS "借方发生额_本月"
FROM
"dwr"."fact_fim_subject_balance" t1
JOIN corp t2 ON t1.corp_code = t2.corp_code
WHERE
t1.acnt_year = '${YEAR(sStart_mon) - 1}'
AND t1.acnt_mon <= '${FORMAT(sStart_mon,"MM")}'
AND t1.subject_code LIKE '2221%'
GROUP BY
LEFT(subject_code,6)
),
subject_result_tq AS (
SELECT
t1.subject_code AS "科目编号",
ABS(SUM("贷方发生额")) AS "应交_同期",
ABS(SUM("贷方发生额_本月")) AS "应交_本月_同期"
FROM
base_info t1
WHERE
t1.subject_code IN ('222102','222105','222104','222113','222114','222106','222107','222110','222108','222109','222112','222118','222125','222121')
GROUP BY
t1.subject_code
UNION ALL
SELECT
'其他税' AS "科目编号",
ABS(SUM(t1."贷方发生额") - SUM(IF(t1.subject_code IN ('222101','222102','222104','222105','222106','222107','222108','222109','222110','222112','222113','222114','222116','2221121','222123','222125'),t1."贷方发生额",0))) AS "应交_同期",
ABS(SUM(t1."贷方发生额_本月") - SUM(IF(t1.subject_code IN ('222101','222102','222104','222105','222106','222107','222108','222109','222110','222112','222113','222114','222116','222121','222123','222125'),t1."贷方发生额_本月",0))) AS "应交_本月_同期"
FROM
base_info t1
UNION ALL
SELECT
'增值税' AS "科目编号",
ABS(SUM(IF(LEFT(t1.subject_code,8) IN ('22210105','22210116','22210117'),t1.credit_amt,0)) + SUM(IF(LEFT(t1.subject_code,6) IN ('222123'),t1.credit_amt,0)) - SUM(IF(LEFT(t1.subject_code,8) IN ('22210101','22210104','22210108','22210110','22210112','22210118'),t1.credit_amt,0))) AS "应交_同期",
ABS(SUM(IF(LEFT(t1.subject_code,8) IN ('22210105','22210116','22210117') AND t1.acnt_mon = '${FORMAT(sStart_mon,"MM")}',t1.credit_amt,0)) + SUM(IF(LEFT(t1.subject_code,6) IN ('222123') AND t1.acnt_mon = '${FORMAT(sStart_mon,"MM")}',t1.credit_amt,0)) - SUM(IF(LEFT(t1.subject_code,8) IN ('22210101','22210104','22210108','22210110','22210112','22210118') AND t1.acnt_mon = '${FORMAT(sStart_mon,"MM")}',t1.debit_amt,0))) AS "应交_本月_同期"
FROM
"dwr"."fact_fim_subject_balance" t1
JOIN corp t2 ON t1.corp_code = t2.corp_code
WHERE
t1.acnt_year = '${YEAR(sStart_mon) - 1}'
AND t1.acnt_mon <= '${FORMAT(sStart_mon,"MM")}'
AND t1.subject_code LIKE '2221%'
UNION ALL
SELECT
'营业收入' AS "科目编号",
SUM(t1.credit_amt) AS "应交_同期",
SUM(IF(t1.acnt_mon = '${FORMAT(sStart_mon,"MM")}',t1.credit_amt,0)) AS "应交_本月_同期"
FROM
"dwr"."fact_fim_subject_balance" t1
JOIN corp t2 ON t1.corp_code = t2.corp_code
WHERE
t1.acnt_year = '${YEAR(sStart_mon) - 1}'
AND t1.acnt_mon <= '${FORMAT(sStart_mon,"MM")}'
AND LEFT(t1.subject_code,4) IN ('6001','6051')
)
SELECT
fin0."税种",
IFNULL(SUM(fin1."应交") / 10000,0) AS "应交",
IFNULL(SUM(fin1."应交_本月") / 10000,0) AS "应交_本月",
IFNULL(SUM(fin2."应交_同期") / 10000,0) AS "应交_同期",
IFNULL(SUM(fin2."应交_本月_同期") / 10000,0) AS "应交_本月_同期"
FROM
( SELECT '增值税' AS "科目编号",'增值税' AS "税种"
UNION ALL
SELECT '222102' AS "科目编号",'消费税' AS "税种"
UNION ALL
SELECT '222105' AS "科目编号",'企业所得税' AS "税种"
UNION ALL
SELECT '222104' AS "科目编号",'城建及附加' AS "税种"
UNION ALL
SELECT '222113' AS "科目编号",'城建及附加' AS "税种"
UNION ALL
SELECT '222114' AS "科目编号",'城建及附加' AS "税种"
UNION ALL
SELECT '222106' AS "科目编号",'个人所得税' AS "税种"
UNION ALL
SELECT '222107' AS "科目编号",'其他税费' AS "税种"
UNION ALL
SELECT '222110' AS "科目编号",'其他税费' AS "税种"
UNION ALL
SELECT '222108' AS "科目编号",'其他税费' AS "税种"
UNION ALL
SELECT '222109' AS "科目编号",'其他税费' AS "税种"
UNION ALL
SELECT '222112' AS "科目编号",'其他税费' AS "税种"
UNION ALL
SELECT '222118' AS "科目编号",'其他税费' AS "税种"
UNION ALL
SELECT '222125' AS "科目编号",'其他税费' AS "税种"
UNION ALL
SELECT '222121' AS "科目编号",'其他税费' AS "税种"
UNION ALL
SELECT '其他税' AS "科目编号",'其他税费' AS "税种"
UNION ALL
SELECT '营业收入' AS "科目编号",'营业收入' AS "税种"
UNION ALL
SELECT '利润总额' AS "科目编号",'利润总额' AS "税种"
) fin0
LEFT JOIN subject_result fin1 ON fin0."科目编号" = fin1."科目编号"
LEFT JOIN subject_result_tq fin2 ON fin0."科目编号" = fin2."科目编号"
GROUP BY
fin0."税种"
ORDER BY
DECODE(fin0."税种",'营业收入',1,'利润总额',2,'增值税',3,'消费税',4,'企业所得税',5,'城建及附加',6,'个人所得税',7,'其他税费',8)

View File

@ -7,7 +7,7 @@ WITH corp AS (
WHERE
corp_type = '实体'
AND (parent_corp_code LIKE '02%' OR corp_code = '0301')
${IF(LEN(sCorpCode)!=0," AND corp_code IN ('"+JOINARRAY(sCorpCode,"','")+"')", "")}
${IF(LEN(sCorp )!=0," AND corp_code IN ('"+ sCorp +"')", "")}
),
base_info AS (
SELECT
@ -20,12 +20,9 @@ WITH corp AS (
FROM
"dwr"."fact_fim_subject_balance" t1
JOIN corp t2 ON t1.corp_code = t2.corp_code
WHERE 1 = 1
-- t1.acnt_year = '${YEAR(sQueryDate)}'
-- AND t1.acnt_mon = '${FORMAT(sQueryDate,"MM")}'
AND concat(acnt_year,'-',acnt_mon) <= '${sQueryDate}'
AND concat(acnt_year,'-',acnt_mon) >= '${sQueryStartDate}'
WHERE t1.acnt_year = '${left(sStart_mon,4)}'
AND t1.acnt_mon <= '${right(sEnd_mon,2)}'
AND t1.acnt_mon >= '${right(sStart_mon,2)}'
AND t1.subject_code LIKE '2221%'
GROUP BY
LEFT(subject_code,6)
@ -65,19 +62,17 @@ WITH corp AS (
FROM
"dwr"."fact_fim_subject_balance" t1
JOIN corp t2 ON t1.corp_code = t2.corp_code
WHERE 1 = 1
-- t1.acnt_year = '${YEAR(sQueryDate)}'
-- AND t1.acnt_mon = '${FORMAT(sQueryDate,"MM")}'
AND concat(acnt_year,'-',acnt_mon) <= '${sQueryDate}'
AND concat(acnt_year,'-',acnt_mon) >= '${sQueryStartDate}'
WHERE t1.acnt_year = '${left(sStart_mon,4)}'
AND t1.acnt_mon <= '${right(sEnd_mon,2)}'
AND t1.acnt_mon >= '${right(sStart_mon,2)}'
AND t1.subject_code LIKE '2221%'
)
SELECT
fin0."税种",
IFNULL(fin1."期初余额",0) AS "期初余额",
IFNULL(fin1."本期应交",0) AS "本期应交",
IFNULL(fin3.,0) AS "实际入库",
IFNULL(fin3.退,0) AS "退税金额"
IFNULL(fin1."期初余额",0) / 10000 AS "期初余额",
IFNULL(fin1."本期应交",0) / 10000 AS "本期应交",
IFNULL(fin3.,0) / 10000 AS "实际入库",
IFNULL(fin3.退,0) / 10000 AS "退税金额"
FROM
( SELECT 1 AS seq, '增值税' AS "科目编号",'增值税' AS "税种"
UNION ALL
@ -120,8 +115,8 @@ WITH corp AS (
,SUM(refund_amt) AS "退税金额"
from dwi.dwi_fim_tax_payed t1
JOIN corp t2 ON t1.corp_code = t2.corp_code
WHERE TO_CHAR(stat_date, 'YYYY-MM') <= '${sQueryDate}'
AND TO_CHAR(stat_date, 'YYYY-MM') >= '${sQueryStartDate}'
WHERE stat_date <= '${CONCATENATE(sEnd_mon,"-01 00:00:00")}'
AND stat_date >= '${CONCATENATE(sStart_mon,"-01 00:00:00")}'
GROUP By tax_name
)fin3
on fin0. = fin3.

View File

@ -0,0 +1,132 @@
WITH corp AS (
SELECT
t1.corp_code,
t1.corp_name,
t2.tax_short_name AS tax_name
FROM
"dwr"."dim_corp" t1
LEFT JOIN "sdi_hzg"."ipt_corp_tax_relation" t2 ON t1.corp_code = t2.corp_code
WHERE
t1.corp_type = '实体'
AND (t1.parent_corp_code LIKE '02%' OR t1.corp_code = '0301')
${IF(LEN(sTax_bureau)!=0," AND t2.tax_name IN ('"+ sTax_bureau +"')", "")}
),
subject AS (
SELECT 1 AS seq, '增值税' AS "科目编号",'增值税' AS "税种" ,'应交税金' AS "类别", 1 AS class_
UNION ALL
SELECT 2 AS seq, '222102' AS "科目编号",'消费税' AS "税种" ,'应交税金' AS "类别", 2 AS class_
UNION ALL
SELECT 3 AS seq, '222105' AS "科目编号",'企业所得税' AS "税种" ,'应交税金' AS "类别", 2 AS class_
UNION ALL
SELECT 4 AS seq, '222104' AS "科目编号",'城建' AS "税种" ,'应交税金' AS "类别", 2 AS class_
UNION ALL
SELECT 5 AS seq, '222113' AS "科目编号",'附加税' AS "税种" ,'应交税金' AS "类别", 2 AS class_
UNION ALL
SELECT 6 AS seq, '222114' AS "科目编号",'附加税' AS "税种" ,'应交税金' AS "类别", 2 AS class_
UNION ALL
SELECT 7 AS seq, '222106' AS "科目编号",'个税' AS "税种" ,'应交税金' AS "类别", 2 AS class_
UNION ALL
SELECT 8 AS seq, '222107' AS "科目编号",'房土税' AS "税种" ,'应交税金' AS "类别", 2 AS class_
UNION ALL
SELECT 9 AS seq, '222110' AS "科目编号",'房土税' AS "税种" ,'应交税金' AS "类别", 2 AS class_
UNION ALL
SELECT 10 AS seq, '其他税' AS "科目编号",'其他税' AS "税种" ,'应交税金' AS "类别", 1 AS class_
),
base_info AS (
SELECT
t1.corp_code,
t1.acnt_mon,
LEFT(t1.subject_code,6) AS subject_code,
SUM(t1.credit_amt) AS credit_amt
FROM
"dwr"."fact_fim_subject_balance" t1
JOIN corp t2 ON t1.corp_code = t2.corp_code
WHERE t1.acnt_year = '${left(sStart_mon,4)}'
AND t1.acnt_mon = '${right(sStart_mon,2)}'
AND t1.subject_code LIKE '2221%'
GROUP BY
LEFT(t1.subject_code,6),
t1.corp_code,
t1.acnt_mon
),
subject_result AS (
SELECT
t2.corp_code,
t1."类别",
t1."税种",
SUM(t2.credit_amt) AS "本年累计",
SUM(IF(t2.acnt_mon = '${right(sStart_mon,2)}',t2.credit_amt,0)) AS "本月"
FROM
subject t1
LEFT JOIN base_info t2 ON t1."科目编号" = t2.subject_code
WHERE
t1.class_ = 2
GROUP BY
t2.corp_code,
t1."类别",
t1."税种"
UNION ALL
SELECT
t1.corp_code,
'应交税金' AS "类别",
'其他税' AS "税种",
SUM(t1.credit_amt) - SUM(IF(t1.subject_code IN ('222101','222102','222104','222105','222106','222107','222110','222113','222114','222116','222123'),t1.credit_amt,0)) AS "本年累计",
SUM(IF(t1.acnt_mon = '${right(sStart_mon,2)}',t1.credit_amt,0)) - SUM(IF(t1.subject_code IN ('222101','222102','222104','222105','222106','222107','222110','222113','222114','222116','222123') AND t1.acnt_mon = '${right(sStart_mon,2)}',t1.credit_amt,0)) AS "本月"
FROM
base_info t1
GROUP BY
t1.corp_code
UNION ALL
SELECT
t1.corp_code,
'应交税金' AS "类别",
'增值税' AS "税种",
SUM(IF(LEFT(t1.subject_code,8) IN ('22210105','22210116','22210117'),t1.credit_amt,0)) + SUM(IF(LEFT(t1.subject_code,6) IN ('222123'),t1.credit_amt,0)) - SUM(IF(LEFT(t1.subject_code,8) IN ('22210101','22210104','22210108','22210110','22210112','22210118'),t1.credit_amt,0)) AS "本年累计",
SUM(IF(LEFT(t1.subject_code,8) IN ('22210105','22210116','22210117') AND t1.acnt_mon = '${right(sStart_mon,2)}' ,t1.credit_amt,0)) + SUM(IF(LEFT(t1.subject_code,6) IN ('222123') AND t1.acnt_mon = '${right(sStart_mon,2)}',t1.credit_amt,0)) - SUM(IF(LEFT(t1.subject_code,8) IN ('22210101','22210104','22210108','22210110','22210112','22210118') AND t1.acnt_mon = '${right(sStart_mon,2)}',t1.credit_amt,0)) AS "本月"
FROM
"dwr"."fact_fim_subject_balance" t1
JOIN corp t2 ON t1.corp_code = t2.corp_code
WHERE t1.acnt_year = '${left(sStart_mon,4)}'
AND t1.acnt_mon = '${right(sStart_mon,2)}'
AND t1.subject_code LIKE '2221%'
GROUP BY
t1.corp_code
)
SELECT
fin0.tax_name,
fin1."税种",
fin1."类别",
ABS(IFNULL(SUM(fin2."本年累计"),0)) / 10000 AS "本年累计",
ABS(IFNULL(SUM(fin2."本月"),0)) / 10000 AS "本月",
fin1.seq
FROM
corp fin0
LEFT JOIN
(
SELECT
"税种",
"类别",
MAX(seq) AS seq
FROM
subject
GROUP BY
"税种",
"类别"
) fin1 ON 1=1
LEFT JOIN subject_result fin2 ON fin0.corp_code = fin2.corp_code AND fin1."税种" = fin2."税种"
GROUP BY
fin0.tax_name,
fin1."税种",
fin1."类别",
fin1.seq
ORDER BY
fin1.seq,
DECODE(fin0.tax_name,'古蔺',1,'龙马潭',2,'叙永',3,'合江',4,'成都',5,'深圳',6,'香港',7,'北京',8,'上海',9,'峨眉山',10,'景德镇',11,'海南',12)

View File

@ -0,0 +1,126 @@
WITH corp AS (
SELECT
t1.corp_code,
t1.corp_name,
t2.tax_name
FROM
"dwr"."dim_corp" t1
JOIN "sdi_hzg"."ipt_corp_tax_relation" t2 ON t1.corp_code = t2.corp_code
WHERE
t1.corp_type = '实体'
AND (t1.parent_corp_code LIKE '02%' OR t1.corp_code = '0301')
${IF(LEN(sCorp )!=0," AND t1.corp_code IN ('"+ sCorp +"')", "")}
),
subject AS (
SELECT 1 AS seq, '增值税' AS "科目编号",'增值税' AS "税种" ,'应交税金' AS "类别", 1 AS class_
UNION ALL
SELECT 2 AS seq, '222102' AS "科目编号",'消费税' AS "税种" ,'应交税金' AS "类别", 2 AS class_
UNION ALL
SELECT 3 AS seq, '222105' AS "科目编号",'企业所得税' AS "税种" ,'应交税金' AS "类别", 2 AS class_
UNION ALL
SELECT 4 AS seq, '222104' AS "科目编号",'城建' AS "税种" ,'应交税金' AS "类别", 2 AS class_
UNION ALL
SELECT 5 AS seq, '222113' AS "科目编号",'附加税' AS "税种" ,'应交税金' AS "类别", 2 AS class_
UNION ALL
SELECT 6 AS seq, '222114' AS "科目编号",'附加税' AS "税种" ,'应交税金' AS "类别", 2 AS class_
UNION ALL
SELECT 7 AS seq, '222106' AS "科目编号",'个税' AS "税种" ,'应交税金' AS "类别", 2 AS class_
UNION ALL
SELECT 8 AS seq, '222107' AS "科目编号",'房土税' AS "税种" ,'应交税金' AS "类别", 2 AS class_
UNION ALL
SELECT 9 AS seq, '222110' AS "科目编号",'房土税' AS "税种" ,'应交税金' AS "类别", 2 AS class_
UNION ALL
SELECT 10 AS seq, '其他税' AS "科目编号",'其他税' AS "税种" ,'应交税金' AS "类别", 1 AS class_
),
base_info AS (
SELECT
t1.corp_code,
t1.acnt_mon,
LEFT(t1.subject_code,6) AS subject_code,
SUM(t1.credit_amt) AS credit_amt
FROM
"dwr"."fact_fim_subject_balance" t1
JOIN corp t2 ON t1.corp_code = t2.corp_code
WHERE t1.acnt_year = '${left(sStart_mon,4)}'
AND t1.acnt_mon = '${right(sStart_mon,2)}'
AND t1.subject_code LIKE '2221%'
GROUP BY
LEFT(t1.subject_code,6),
t1.corp_code,
t1.acnt_mon
),
subject_result AS (
SELECT
t2.corp_code,
t1."类别",
t1."税种",
SUM(t2.credit_amt) AS "本年累计",
SUM(IF(t2.acnt_mon = '${right(sStart_mon,2)}',t2.credit_amt,0)) AS "本月"
FROM
subject t1
LEFT JOIN base_info t2 ON t1."科目编号" = t2.subject_code
WHERE
t1.class_ = 2
GROUP BY
t2.corp_code,
t1."类别",
t1."税种"
UNION ALL
SELECT
t1.corp_code,
'应交税金' AS "类别",
'其他税' AS "税种",
SUM(t1.credit_amt) - SUM(IF(t1.subject_code IN ('222101','222102','222104','222105','222106','222107','222110','222113','222114','222116','222123'),t1.credit_amt,0)) AS "本年累计",
SUM(IF(t1.acnt_mon = '${right(sStart_mon,2)}',t1.credit_amt,0)) - SUM(IF(t1.subject_code IN ('222101','222102','222104','222105','222106','222107','222110','222113','222114','222116','222123') AND t1.acnt_mon = '${right(sStart_mon,2)}',t1.credit_amt,0)) AS "本月"
FROM
base_info t1
GROUP BY
t1.corp_code
UNION ALL
SELECT
t1.corp_code,
'应交税金' AS "类别",
'增值税' AS "税种",
ABS(SUM(IF(LEFT(t1.subject_code,8) IN ('22210105','22210116','22210117'),t1.credit_amt,0)) + SUM(IF(LEFT(t1.subject_code,6) IN ('222123'),t1.credit_amt,0)) - SUM(IF(LEFT(t1.subject_code,8) IN ('22210101','22210104','22210108','22210110','22210112','22210118'),t1.credit_amt,0))) AS "本年累计",
ABS(SUM(IF(LEFT(t1.subject_code,8) IN ('22210105','22210116','22210117') AND t1.acnt_mon = '${right(sStart_mon,2)}',t1.credit_amt,0)) + SUM(IF(LEFT(t1.subject_code,6) IN ('222123') AND t1.acnt_mon = '${right(sStart_mon,2)}',t1.credit_amt,0)) - SUM(IF(LEFT(t1.subject_code,8) IN ('22210101','22210104','22210108','22210110','22210112','22210118') AND t1.acnt_mon = '${right(sStart_mon,2)}',t1.credit_amt,0))) AS "本月"
FROM
"dwr"."fact_fim_subject_balance" t1
JOIN corp t2 ON t1.corp_code = t2.corp_code
WHERE t1.acnt_year = '${left(sStart_mon,4)}'
AND t1.acnt_mon = '${right(sStart_mon,2)}'
AND t1.subject_code LIKE '2221%'
GROUP BY
t1.corp_code
)
SELECT
fin0.corp_code,
fin0.corp_name,
fin1."税种",
IFNULL(fin2."本年累计",0) / 10000 AS "本年累计",
IFNULL(fin2."本月",0) / 10000 AS "本月"
FROM
corp fin0
LEFT JOIN
(
SELECT
"税种",
"类别",
MAX(seq) AS seq
FROM
subject
GROUP BY
"税种",
"类别"
) fin1 ON 1=1
LEFT JOIN subject_result fin2 ON fin0.corp_code = fin2.corp_code AND fin1."税种" = fin2."税种"
ORDER BY
fin1.seq,
fin0.corp_code

View File

@ -5,30 +5,30 @@ WITH corp AS (
FROM dwr.dim_corp
WHERE corp_type = '实体'
AND (parent_corp_code LIKE '02%' OR corp_code = '0301')
${IF(LEN(sCorpCode)!=0," AND corp_code IN ('"+JOINARRAY(sCorpCode,"','")+"')", "")}
${IF(LEN(sCorp)!=0," AND corp_code IN ('"+ sCorp +"')", "")}
),
base_info_curr AS (
SELECT
A.subject_code AS subject_code -- 科目编码
,SUM(A.debit_amt) AS debit_amt_y -- 借方金额_当年累计
,SUM(IF(A.acnt_mon = '${FORMAT(sQueryDate,"MM")}',A.debit_amt,0)) AS debit_amt_m -- 借方金额_当月累计
,SUM(IF(A.acnt_mon = '${FORMAT(sStart_mon,"MM")}',A.debit_amt,0)) AS debit_amt_m -- 借方金额_当月累计
FROM dwr.fact_fim_subject_balance A-- 科目余额
JOIN corp B ON A.corp_code = B.corp_code
WHERE A.subject_code like '6601%'
AND A.acnt_year = '${YEAR(sQueryDate)}'
AND A.acnt_mon <= '${FORMAT(sQueryDate,"MM")}'
AND A.acnt_year = '${YEAR(sStart_mon)}'
AND A.acnt_mon <= '${FORMAT(sStart_mon,"MM")}'
GROUP BY A.subject_code
),
base_info_last AS (
SELECT
A.subject_code AS subject_code -- 科目编码
,SUM(A.debit_amt) AS debit_amt_y -- 借方金额_当年累计
,SUM(IF(A.acnt_mon = '${FORMAT(sQueryDate,"MM")}',A.debit_amt,0)) AS debit_amt_m -- 借方金额_当月累计
,SUM(IF(A.acnt_mon = '${FORMAT(sStart_mon,"MM")}',A.debit_amt,0)) AS debit_amt_m -- 借方金额_当月累计
FROM dwr.fact_fim_subject_balance A-- 科目余额
JOIN corp B ON A.corp_code = B.corp_code
WHERE A.subject_code like '6601%'
AND A.acnt_year = '${YEAR(sQueryDate) - 1}'
AND A.acnt_mon <= '${FORMAT(sQueryDate,"MM")}'
AND A.acnt_year = '${YEAR(sStart_mon) - 1}'
AND A.acnt_mon <= '${FORMAT(sStart_mon,"MM")}'
GROUP BY A.subject_code
),
subject_result AS (

View File

@ -5,7 +5,7 @@ WITH corp AS (
FROM dwr.dim_corp
WHERE corp_type = '实体'
AND (parent_corp_code LIKE '02%' OR corp_code = '0301')
${IF(LEN(sCorpCode)!=0," AND corp_code IN ('"+JOINARRAY(sCorpCode,"','")+"')", "")}
${IF(LEN(sCorp)!=0," AND corp_code IN ('"+ sCorp +"')", "")}
)
SELECT
bill_date -- 制单日期
@ -22,21 +22,27 @@ SELECT
,subject_code -- 科目编码
,subject_name -- 科目名称
,subject_full_name -- 科目全称
,aux_content -- 辅助核算
,debit_amt -- 借方金额
,credit_amt -- 贷方金额
,aux_content -- 辅助核算
,debit_amt / 10000 AS debit_amt -- 借方金额
,credit_amt / 10000 credit_amt -- 贷方金额
,src_bill_codes -- 来源单据号
,acnt_date -- 记账日期
FROM dwi.dwi_fim_voucher
where subject_code like '6601%'
and corp_code in(SELECT corp_code FROM corp)
${if(len(sBillcode)=0," ","AND src_bill_codes = '" + sBillcode +"'")}
-- AND acnt_year = '${YEAR(sQueryDate)}'
-- AND acnt_mon <= '${FORMAT(sQueryDate,"MM")}'
and corp_code in(SELECT corp_code FROM corp)
${if(len(sBill)=0," ","AND src_bill_codes = '" + sBill +"'")}
-- AND acnt_year = '${YEAR(sStart_mon)}'
-- AND acnt_mon <= '${FORMAT(sStart_mon,"MM")}'
-- ${switch(sCalcType
-- ,"m","AND concat(acnt_year,'-',acnt_mon) <= '" + sQueryDate + "' AND concat(acnt_year,'-',acnt_mon) >= '" + sQueryStartDate + "'"
-- ,"y","AND concat(acnt_year,'-',acnt_mon) <= '" + sQueryDate + "' AND concat(acnt_year,'-',acnt_mon) >= '" + sQueryStartDate + "'"
-- )}
${switch(sCalcType
,"m","AND concat(acnt_year,'-',acnt_mon) <= '" + sQueryDate + "' AND concat(acnt_year,'-',acnt_mon) >= '" + sQueryStartDate + "'"
,"y","AND concat(acnt_year,'-',acnt_mon) <= '" + sQueryDate + "' AND concat(acnt_year,'-',acnt_mon) >= '" + sQueryStartDate + "'"
)}
,"m","AND acnt_year = '" + YEAR(sStart_mon) + "' AND acnt_mon = '" + FORMAT(sStart_mon,"MM") + "'"
,"y","AND acnt_year = '" + YEAR(sStart_mon) + "' AND acnt_mon = '" + FORMAT(sStart_mon,"MM") + "'"
)}
${nvl(switch(sSubject
,"0000","AND subject_code like '6601%' AND (subject_code not like '660114%'
AND subject_code not like '660127%'

View File

@ -5,30 +5,30 @@ WITH corp AS (
FROM dwr.dim_corp
WHERE corp_type = '实体'
AND (parent_corp_code LIKE '02%' OR corp_code = '0301')
${IF(LEN(sCorpCode)!=0," AND corp_code IN ('"+JOINARRAY(sCorpCode,"','")+"')", "")}
${IF(LEN(sCorp)!=0," AND corp_code IN ('"+ sCorp +"')", "")}
),
base_info_curr AS (
SELECT
A.subject_code AS subject_code -- 科目编码
,SUM(A.debit_amt) AS debit_amt_y -- 借方金额_当年累计
,SUM(IF(A.acnt_mon = '${FORMAT(sQueryDate,"MM")}',A.debit_amt,0)) AS debit_amt_m -- 借方金额_当月累计
,SUM(IF(A.acnt_mon = '${FORMAT(sStart_mon,"MM")}',A.debit_amt,0)) AS debit_amt_m -- 借方金额_当月累计
FROM dwr.fact_fim_subject_balance A-- 科目余额
JOIN corp B ON A.corp_code = B.corp_code
WHERE A.subject_code like '6602%'
AND A.acnt_year = '${YEAR(sQueryDate)}'
AND A.acnt_mon <= '${FORMAT(sQueryDate,"MM")}'
AND A.acnt_year = '${YEAR(sStart_mon)}'
AND A.acnt_mon <= '${FORMAT(sStart_mon,"MM")}'
GROUP BY A.subject_code
),
base_info_last AS (
SELECT
A.subject_code AS subject_code -- 科目编码
,SUM(A.debit_amt) AS debit_amt_y -- 借方金额_当年累计
,SUM(IF(A.acnt_mon = '${FORMAT(sQueryDate,"MM")}',A.debit_amt,0)) AS debit_amt_m -- 借方金额_当月累计
,SUM(IF(A.acnt_mon = '${FORMAT(sStart_mon,"MM")}',A.debit_amt,0)) AS debit_amt_m -- 借方金额_当月累计
FROM dwr.fact_fim_subject_balance A-- 科目余额
JOIN corp B ON A.corp_code = B.corp_code
WHERE A.subject_code like '6602%'
AND A.acnt_year = '${YEAR(sQueryDate) - 1}'
AND A.acnt_mon <= '${FORMAT(sQueryDate,"MM")}'
AND A.acnt_year = '${YEAR(sStart_mon) - 1}'
AND A.acnt_mon <= '${FORMAT(sStart_mon,"MM")}'
GROUP BY A.subject_code
),
subject_result AS (

View File

@ -5,30 +5,30 @@ WITH corp AS (
FROM dwr.dim_corp
WHERE corp_type = '实体'
AND (parent_corp_code LIKE '02%' OR corp_code = '0301')
${IF(LEN(sCorpCode)!=0," AND corp_code IN ('"+JOINARRAY(sCorpCode,"','")+"')", "")}
${IF(LEN(sCorp)!=0," AND corp_code IN ('"+ sCorp +"')", "")}
),
base_info_curr AS (
SELECT
A.subject_code AS subject_code -- 科目编码
,SUM(A.debit_amt) AS debit_amt_y -- 借方金额_当年累计
,SUM(IF(A.acnt_mon = '${FORMAT(sQueryDate,"MM")}',A.debit_amt,0)) AS debit_amt_m -- 借方金额_当月累计
,SUM(IF(A.acnt_mon = '${FORMAT(sStart_mon,"MM")}',A.debit_amt,0)) AS debit_amt_m -- 借方金额_当月累计
FROM dwr.fact_fim_subject_balance A-- 科目余额
JOIN corp B ON A.corp_code = B.corp_code
WHERE A.subject_code like '6604%'
AND A.acnt_year = '${YEAR(sQueryDate)}'
AND A.acnt_mon <= '${FORMAT(sQueryDate,"MM")}'
AND A.acnt_year = '${YEAR(sStart_mon)}'
AND A.acnt_mon <= '${FORMAT(sStart_mon,"MM")}'
GROUP BY A.subject_code
),
base_info_last AS (
SELECT
A.subject_code AS subject_code -- 科目编码
,SUM(A.debit_amt) AS debit_amt_y -- 借方金额_当年累计
,SUM(IF(A.acnt_mon = '${FORMAT(sQueryDate,"MM")}',A.debit_amt,0)) AS debit_amt_m -- 借方金额_当月累计
,SUM(IF(A.acnt_mon = '${FORMAT(sStart_mon,"MM")}',A.debit_amt,0)) AS debit_amt_m -- 借方金额_当月累计
FROM dwr.fact_fim_subject_balance A-- 科目余额
JOIN corp B ON A.corp_code = B.corp_code
WHERE A.subject_code like '6604%'
AND A.acnt_year = '${YEAR(sQueryDate) - 1}'
AND A.acnt_mon <= '${FORMAT(sQueryDate,"MM")}'
AND A.acnt_year = '${YEAR(sStart_mon) - 1}'
AND A.acnt_mon <= '${FORMAT(sStart_mon,"MM")}'
GROUP BY A.subject_code
),
subject_result AS (
@ -149,7 +149,6 @@ WITH corp AS (
AND subject_code NOT like '660409%'
AND subject_code NOT like '660408%'
AND subject_code NOT like '660402%')
)
SELECT
subject_name AS subject_name -- 科目名称

View File

@ -5,30 +5,30 @@ WITH corp AS (
FROM dwr.dim_corp
WHERE corp_type = '实体'
AND (parent_corp_code LIKE '02%' OR corp_code = '0301')
${IF(LEN(sCorpCode)!=0," AND corp_code IN ('"+JOINARRAY(sCorpCode,"','")+"')", "")}
${IF(LEN(sCorp)!=0," AND corp_code IN ('"+ sCorp +"')", "")}
),
base_info_curr AS (
SELECT
A.subject_code AS subject_code -- 科目编码
,SUM(A.debit_amt) AS debit_amt_y -- 借方金额_当年累计
,SUM(IF(A.acnt_mon = '${FORMAT(sQueryDate,"MM")}',A.debit_amt,0)) AS debit_amt_m -- 借方金额_当月累计
,SUM(IF(A.acnt_mon = '${FORMAT(sStart_mon,"MM")}',A.debit_amt,0)) AS debit_amt_m -- 借方金额_当月累计
FROM dwr.fact_fim_subject_balance A-- 科目余额
JOIN corp B ON A.corp_code = B.corp_code
WHERE A.subject_code like '6603%'
AND A.acnt_year = '${YEAR(sQueryDate)}'
AND A.acnt_mon <= '${FORMAT(sQueryDate,"MM")}'
AND A.acnt_year = '${YEAR(sStart_mon)}'
AND A.acnt_mon <= '${FORMAT(sStart_mon,"MM")}'
GROUP BY A.subject_code
),
base_info_last AS (
SELECT
A.subject_code AS subject_code -- 科目编码
,SUM(A.debit_amt) AS debit_amt_y -- 借方金额_当年累计
,SUM(IF(A.acnt_mon = '${FORMAT(sQueryDate,"MM")}',A.debit_amt,0)) AS debit_amt_m -- 借方金额_当月累计
,SUM(IF(A.acnt_mon = '${FORMAT(sStart_mon,"MM")}',A.debit_amt,0)) AS debit_amt_m -- 借方金额_当月累计
FROM dwr.fact_fim_subject_balance A-- 科目余额
JOIN corp B ON A.corp_code = B.corp_code
WHERE A.subject_code like '6603%'
AND A.acnt_year = '${YEAR(sQueryDate) - 1}'
AND A.acnt_mon <= '${FORMAT(sQueryDate,"MM")}'
AND A.acnt_year = '${YEAR(sStart_mon) - 1}'
AND A.acnt_mon <= '${FORMAT(sStart_mon,"MM")}'
GROUP BY A.subject_code
),
subject_result AS (
@ -68,26 +68,26 @@ WITH corp AS (
,0 AS debit_amt_last_y -- 借方金额_上年累计
FROM base_info_curr
WHERE subject_code LIKE '660304%'
UNION ALL
SELECT
'其他' AS subject_name -- 科目名称
,SUM(CASE WHEN subject_code LIKE '6603%' THEN debit_amt_m ELSE 0 END)
- SUM(CASE WHEN subject_code LIKE '660301%' THEN debit_amt_m ELSE 0 END)
- SUM(CASE WHEN subject_code LIKE '660303%' THEN debit_amt_m ELSE 0 END)
- SUM(CASE WHEN subject_code LIKE '660304%' THEN debit_amt_m ELSE 0 END)
+ SUM(CASE WHEN subject_code LIKE '660302%' THEN debit_amt_m ELSE 0 END)
AS debit_amt_m -- 借方金额_当月累计
,SUM(CASE WHEN subject_code LIKE '6603%' THEN debit_amt_y ELSE 0 END)
- SUM(CASE WHEN subject_code LIKE '660301%' THEN debit_amt_y ELSE 0 END)
- SUM(CASE WHEN subject_code LIKE '660303%' THEN debit_amt_y ELSE 0 END)
- SUM(CASE WHEN subject_code LIKE '660304%' THEN debit_amt_y ELSE 0 END)
+ SUM(CASE WHEN subject_code LIKE '660302%' THEN debit_amt_y ELSE 0 END)
-- UNION ALL
-- SELECT
-- '其他' AS subject_name -- 科目名称
-- ,SUM(CASE WHEN subject_code LIKE '6603%' THEN debit_amt_m ELSE 0 END)
-- - SUM(CASE WHEN subject_code LIKE '660301%' THEN debit_amt_m ELSE 0 END)
-- - SUM(CASE WHEN subject_code LIKE '660303%' THEN debit_amt_m ELSE 0 END)
-- - SUM(CASE WHEN subject_code LIKE '660304%' THEN debit_amt_m ELSE 0 END)
-- + SUM(CASE WHEN subject_code LIKE '660302%' THEN debit_amt_m ELSE 0 END)
-- AS debit_amt_m -- 借方金额_当月累计
-- ,SUM(CASE WHEN subject_code LIKE '6603%' THEN debit_amt_y ELSE 0 END)
-- - SUM(CASE WHEN subject_code LIKE '660301%' THEN debit_amt_y ELSE 0 END)
-- - SUM(CASE WHEN subject_code LIKE '660303%' THEN debit_amt_y ELSE 0 END)
-- - SUM(CASE WHEN subject_code LIKE '660304%' THEN debit_amt_y ELSE 0 END)
-- + SUM(CASE WHEN subject_code LIKE '660302%' THEN debit_amt_y ELSE 0 END)
AS debit_amt_y -- 借方金额_当年累计
,0 AS debit_amt_last_m -- 借方金额_上年同期
,0 AS debit_amt_last_y -- 借方金额_上年累计
FROM base_info_curr
WHERE subject_code like '6603%'
-- AS debit_amt_y -- 借方金额_当年累计
-- ,0 AS debit_amt_last_m -- 借方金额_上年同期
-- ,0 AS debit_amt_last_y -- 借方金额_上年累计
-- FROM base_info_curr
-- WHERE subject_code like '6603%'
UNION ALL
-- 上期统计
SELECT
@ -125,27 +125,27 @@ WITH corp AS (
,SUM(debit_amt_y) AS debit_amt_last_y -- 借方金额_上年累计
FROM base_info_last
WHERE subject_code LIKE '660304%'
UNION ALL
SELECT
'其他' AS subject_name -- 科目名称
,0 AS debit_amt_m -- 借方金额_当月累计
,0 AS debit_amt_y -- 借方金额_当年累计
,SUM(CASE WHEN subject_code LIKE '6603%' THEN debit_amt_m ELSE 0 END)
- SUM(CASE WHEN subject_code LIKE '660301%' THEN debit_amt_m ELSE 0 END)
- SUM(CASE WHEN subject_code LIKE '660303%' THEN debit_amt_m ELSE 0 END)
- SUM(CASE WHEN subject_code LIKE '660304%' THEN debit_amt_m ELSE 0 END)
+ SUM(CASE WHEN subject_code LIKE '660302%' THEN debit_amt_m ELSE 0 END)
AS debit_amt_last_m -- 借方金额_上年同期
,SUM(CASE WHEN subject_code LIKE '6603%' THEN debit_amt_y ELSE 0 END)
- SUM(CASE WHEN subject_code LIKE '660301%' THEN debit_amt_y ELSE 0 END)
- SUM(CASE WHEN subject_code LIKE '660303%' THEN debit_amt_y ELSE 0 END)
- SUM(CASE WHEN subject_code LIKE '660304%' THEN debit_amt_y ELSE 0 END)
+ SUM(CASE WHEN subject_code LIKE '660302%' THEN debit_amt_y ELSE 0 END)
AS debit_amt_last_y -- 借方金额_上年累计
FROM base_info_last
WHERE subject_code like '6603%'
-- UNION ALL
-- SELECT
-- '其他' AS subject_name -- 科目名称
-- ,0 AS debit_amt_m -- 借方金额_当月累计
-- ,0 AS debit_amt_y -- 借方金额_当年累计
-- ,SUM(CASE WHEN subject_code LIKE '6603%' THEN debit_amt_m ELSE 0 END)
-- - SUM(CASE WHEN subject_code LIKE '660301%' THEN debit_amt_m ELSE 0 END)
-- - SUM(CASE WHEN subject_code LIKE '660303%' THEN debit_amt_m ELSE 0 END)
-- - SUM(CASE WHEN subject_code LIKE '660304%' THEN debit_amt_m ELSE 0 END)
-- + SUM(CASE WHEN subject_code LIKE '660302%' THEN debit_amt_m ELSE 0 END)
-- AS debit_amt_last_m -- 借方金额_上年同期
-- ,SUM(CASE WHEN subject_code LIKE '6603%' THEN debit_amt_y ELSE 0 END)
-- - SUM(CASE WHEN subject_code LIKE '660301%' THEN debit_amt_y ELSE 0 END)
-- - SUM(CASE WHEN subject_code LIKE '660303%' THEN debit_amt_y ELSE 0 END)
-- - SUM(CASE WHEN subject_code LIKE '660304%' THEN debit_amt_y ELSE 0 END)
-- + SUM(CASE WHEN subject_code LIKE '660302%' THEN debit_amt_y ELSE 0 END)
--
-- AS debit_amt_last_y -- 借方金额_上年累计
--
-- FROM base_info_last
-- WHERE subject_code like '6603%'
)
SELECT
subject_name AS subject_name -- 科目名称

View File

@ -79,7 +79,7 @@ ORDER BY a.month
select
a.year -- 年度
,CONCAT(a.month,'月达成') AS month -- 月度
,a.month -- 月度
,a.deal_code -- 主经销商编码
,a.deal_name -- 主经销商名称
,a.src_deal_code -- 子经销商编码
@ -91,43 +91,43 @@ select
,a.plan_item -- 计划项目
,a.plan_pi_name -- 计划品项
-- 月份的
,SUM(a.m_plan_in_num) AS m_plan_in_num -- 计划内瓶数
,SUM(a.m_plan_in_pack) AS m_plan_in_pack -- 计划内件数
,SUM(a.m_plan_in_ton) AS m_plan_in_ton -- 计划内吨数
,SUM(a.m_plan_in_amt) / 10000 AS m_plan_in_amt -- 计划内金额
,SUM(a.m_plan_out_num) AS m_plan_out_num -- 计划外瓶数
,SUM(a.m_plan_out_pack) AS m_plan_out_pack -- 计划外件数
,SUM(a.m_plan_out_ton) AS m_plan_out_ton-- 计划外吨数
,SUM(a.m_plan_out_amt) / 10000 AS m_plan_out_amt -- 计划外金额
,a.m_plan_in_num AS m_plan_in_num -- 计划内瓶数
,a.m_plan_in_pack AS m_plan_in_pack -- 计划内件数
,a.m_plan_in_ton AS m_plan_in_ton -- 计划内吨数
,a.m_plan_in_amt / 10000 AS m_plan_in_amt -- 计划内金额
,a.m_plan_out_num AS m_plan_out_num -- 计划外瓶数
,a.m_plan_out_pack AS m_plan_out_pack -- 计划外件数
,a.m_plan_out_ton AS m_plan_out_ton-- 计划外吨数
,a.m_plan_out_amt / 10000 AS m_plan_out_amt -- 计划外金额
-- 合同约定
,SUM(a.ct_plan_in_num ) AS ct_plan_in_num -- 合同约定计划内瓶数
,SUM(a.ct_plan_in_pack ) AS ct_plan_in_pack -- 合同约定计划内件数
,SUM(a.ct_plan_in_ton ) AS ct_plan_in_ton -- 合同约定计划内吨数
,SUM(a.ct_plan_in_amt) / 10000 AS ct_plan_in_amt -- 合同约定计划内金额
,SUM(a.ct_plan_out_num) AS ct_plan_out_num -- 合同约定计划外瓶数
,SUM(a.ct_plan_out_pack) AS ct_plan_out_pack -- 合同约定计划外件数
,SUM(a.ct_plan_out_ton) AS ct_plan_out_ton -- 合同约定计划外吨数
,SUM(a.ct_plan_out_amt) / 10000 AS ct_plan_out_amt -- 合同约定计划外金额
,a.ct_plan_in_num AS ct_plan_in_num -- 合同约定计划内瓶数
,a.ct_plan_in_pack AS ct_plan_in_pack -- 合同约定计划内件数
,a.ct_plan_in_ton AS ct_plan_in_ton -- 合同约定计划内吨数
,a.ct_plan_in_amt / 10000 AS ct_plan_in_amt -- 合同约定计划内金额
,a.ct_plan_out_num AS ct_plan_out_num -- 合同约定计划外瓶数
,a.ct_plan_out_pack AS ct_plan_out_pack -- 合同约定计划外件数
,a.ct_plan_out_ton AS ct_plan_out_ton -- 合同约定计划外吨数
,a.ct_plan_out_amt / 10000 AS ct_plan_out_amt -- 合同约定计划外金额
-- 增加计划
,SUM(a.add_plan_in_num ) AS add_plan_in_num -- 增加计划内瓶数
,SUM(a.add_plan_in_pack ) AS add_plan_in_pack -- 增加计划内件数
,SUM(a.add_plan_in_ton ) AS add_plan_in_ton -- 增加计划内吨数
,SUM(a.add_plan_in_amt) / 10000 AS add_plan_in_amt-- 增加计划内金额
,SUM(a.add_plan_out_num ) AS add_plan_out_num -- 增加计划外瓶数
,SUM(a.add_plan_out_pack ) AS add_plan_out_pack -- 增加计划外件数
,SUM(a.add_plan_out_ton ) AS add_plan_out_ton -- 增加计划外吨数
,SUM(a.add_plan_out_amt) / 10000 ASadd_plan_out_amt -- 增加计划外金额
,a.add_plan_in_num AS add_plan_in_num -- 增加计划内瓶数
,a.add_plan_in_pack AS add_plan_in_pack -- 增加计划内件数
,a.add_plan_in_ton AS add_plan_in_ton -- 增加计划内吨数
,a.add_plan_in_amt / 10000 AS add_plan_in_amt-- 增加计划内金额
,a.add_plan_out_num AS add_plan_out_num -- 增加计划外瓶数
,a.add_plan_out_pack AS add_plan_out_pack -- 增加计划外件数
,a.add_plan_out_ton AS add_plan_out_ton -- 增加计划外吨数
,a.add_plan_out_amt / 10000 ASadd_plan_out_amt -- 增加计划外金额
-- 减少计划
,SUM(a.cut_plan_in_num ) AS cut_plan_in_num -- 减少计划内瓶数
,SUM(a.cut_plan_in_pack ) AS cut_plan_in_pack -- 减少计划内件数
,SUM(a.cut_plan_in_ton ) AS cut_plan_in_ton -- 减少计划内吨数
,SUM(a.cut_plan_in_amt ) / 10000 AS cut_plan_in_amt-- 减少计划内金额
,SUM(a.cut_plan_out_num ) AS cut_plan_out_num -- 减少计划外瓶数
,SUM(a.cut_plan_out_park ) AS cut_plan_out_park -- 减少计划外件数
,SUM(a.cut_plan_out_ton ) AS cut_plan_out_ton -- 减少计划外吨数
,SUM(a.cut_plan_out_amt) / 10000 AS cut_plan_out_amt -- 减少加计划外金额
,a.cut_plan_in_num AS cut_plan_in_num -- 减少计划内瓶数
,a.cut_plan_in_pack AS cut_plan_in_pack -- 减少计划内件数
,a.cut_plan_in_ton AS cut_plan_in_ton -- 减少计划内吨数
,a.cut_plan_in_amt / 10000 AS cut_plan_in_amt-- 减少计划内金额
,a.cut_plan_out_num AS cut_plan_out_num -- 减少计划外瓶数
,a.cut_plan_out_park AS cut_plan_out_park -- 减少计划外件数
,a.cut_plan_out_ton AS cut_plan_out_ton -- 减少计划外吨数
,a.cut_plan_out_amt / 10000 AS cut_plan_out_amt -- 减少加计划外金额
from
(
SELECT
@ -182,14 +182,13 @@ from
,CASE WHEN (plan_item = '计划调整' AND plan_in_num < 0) THEN plan_out_ton ELSE 0 END AS cut_plan_out_ton -- 减少计划外吨数
,CASE WHEN (plan_item = '计划调整' AND plan_in_num < 0) THEN plan_out_amt ELSE 0 END AS cut_plan_out_amt -- 减少加计划外金额
FROM dm.dm_cus_flavour_plan_executed
WHERE year = '${SYear}'
-- 计划类型
${if(len(sPlantype) == 0,"","and plan_type IN ('"+sPlantype+"')")}
-- 计划品项
${if(len(sPlanpi) == 0,"","and plan_pi_name IN ('"+sPlanpi+"')")}
-- 子主经销商
${if(sDeal == 1,if(len(sDealName) == 0,"","and deal_code IN ('"+ sDealName +"')"),if(len(sDealName) == 0,"","and src_deal_code IN ('"+ sDealName +"')"))}
WHERE year = '${sStart_year}'
-- 计划类型
${if(len(sPlan_type) == 0,"","and plan_type IN ('"+sPlan_type+"')")}
-- 计划品项
${if(len(sPlan_Pi) == 0,"","and plan_pi_name IN ('"+sPlan_Pi+"')")}
-- 经销商
${if(sIs_srcdeal == '2',if(len(sDeal) == 0,"","and deal_code IN ('"+ sDeal+"')"),if(len(sDeal) == 0,"","and src_deal_code IN ('"+ sDeal +"')"))}
)a
left join dwr.dim_department d on a.city_unit_code=d.dept_code
left join
@ -207,12 +206,12 @@ on a.src_deal_code=stp.deal_code
and d.fist_dept_code=stp.bu_code
WHERE 1=1
-- 事业部
${if(len(sBu) == 0,"","and stp.bu_code IN ('"+sBu+"')")}
${if(len(sBu) == 0,"","and stp.bu_code IN ('"+sBu+"')")}
-- 经销商是否终止
${if(len(SIsstop) == 0,"","and nvl(stp.is_suspend,'0') = '"+SIsstop+"'")}
GROUP BY
${if(len(sIs_stop_deal) == 0,"","and nvl(stp.is_suspend,'0') = '"+sIs_stop_deal+"'")}
ORDER BY
a.year -- 年度
,CONCAT(a.month,'月达成') -- 月度
,a.month -- 月度
,a.deal_code -- 主经销商编码
,a.deal_name -- 主经销商名称
,a.src_deal_code -- 子经销商编码
@ -223,7 +222,7 @@ GROUP BY
,a.plan_type -- 计划类型
,a.plan_item -- 计划项目
,a.plan_pi_name -- 计划品项
ORDER BY CONCAT(a.month,'月达成')
;
@ -247,76 +246,7 @@ ${if(len(sPlantype) == 0,"","and plan_type IN ('"+sPlantype+"')")}
${if(sDeal == 1,if(len(sDealName) == 0,"","and deal_code IN ('"+ sDealName+"')"),if(len(sDealName) == 0,"","and src_deal_code IN ('"+ sDealName +"')"))}
-- ======================================
-- 月度维度
-- ======================================
select
period_year,
quarter,
month,
period_year||month as "年月"
from dwr.dim_date
where period_year<=to_char(sysdate-30,'yyyy') + 2
and period_year>='2019'
group by period_year,quarter,month
order by period_year,quarter,month;
-- ======================================
-- 产品维度
-- ======================================
select product_code,
product_name,
pi_code,
pi_name,
case when product_name like '%T3%' then 'T3'
when product_name like '%T6%' then 'T6'
when product_name like '%T8%' then 'T8'
when product_name like '%T9%' then 'T9'
when product_name like '%鉴赏%' then '鉴赏级'
when product_name like '%黑马特%' and product_name not like '%郎牌·%黑马特%'
then '黑马特1.0'
when product_name like '%郎牌·%黑马特%'
then '黑马特2.0'
when product_name like '%白马特%' and product_name not like '%郎牌·%白马特%'
then '白马特1.0'
when product_name like '%郎牌·%白马特%'
then '白马特2.0'
when product_name like '%新郎酒%' then '新郎酒'
when product_name ~ '皇福特|鸿福特' then '福系列'
else pi_name end as bu_pi_name,
pl_code,
pl_name,
price,
spec,
base_unit,
pack_unit,
pack_base_num,
pack_length,
pack_width,
pack_height,
length_unit,
pack_volume,
volume_unit,
gross_weight,
weight_unit,
box_number,
bottle_number,
sale_status,
prod_status,
pr_code,
report_pi_name,
pr_name,
bu_code,
d.dept_name as bu_name,
aroma_type,
plan_type,
plan_pi_name,
plan_pi_code,
alc_degree,
price_out
from dwr.dim_product a
left join dwr.dim_department d on a.bu_code=d.dept_code
SELECT CONCAT('数据更新日期:',LEFT(MAX(update_time),19)) AS update_time FROM dm.dm_cus_flavour_plan_executed

View File

@ -46,7 +46,7 @@ FROM
-- 市
${if(len(sCity) == 0,"","and city_name IN ('"+ sCity+"')")}
-- 经销商
${if(len(sDeal) == 0,"","and deal_code IN ('"+sDeal+"')")}
${if(sIs_srcdeal == '2',if(len(sDeal) == 0,"","and deal_code IN ('"+ sDeal+"')"),if(len(sDeal) == 0,"","and src_deal_code IN ('"+ sDeal +"')"))}
-- 产品线
${if(len(sPl) == 0,"","and pl_name IN ('"+ sPl+"')")}
-- 品项
@ -103,7 +103,7 @@ FROM
-- 市
${if(len(sCity) == 0,"","and city_name IN ('"+ sCity+"')")}
-- 经销商
${if(len(sDeal) == 0,"","and deal_code IN ('"+sDeal+"')")}
${if(sIs_srcdeal == '2',if(len(sDeal) == 0,"","and deal_code IN ('"+ sDeal+"')"),if(len(sDeal) == 0,"","and src_deal_code IN ('"+ sDeal +"')"))}
-- 产品线
${if(len(sPl) == 0,"","and pl_name IN ('"+ sPl+"')")}
-- 品项
@ -161,7 +161,7 @@ FROM
-- 市
${if(len(sCity) == 0,"","and city_name IN ('"+ sCity+"')")}
-- 经销商
${if(len(sDeal) == 0,"","and deal_code IN ('"+sDeal+"')")}
${if(sIs_srcdeal == '2',if(len(sDeal) == 0,"","and deal_code IN ('"+ sDeal+"')"),if(len(sDeal) == 0,"","and src_deal_code IN ('"+ sDeal +"')"))}
-- 产品线
${if(len(sPl) == 0,"","and pl_name IN ('"+ sPl+"')")}
-- 品项
@ -217,7 +217,7 @@ FROM
-- 市
${if(len(sCity) == 0,"","and city_name IN ('"+ sCity+"')")}
-- 经销商
${if(len(sDeal) == 0,"","and deal_code IN ('"+sDeal+"')")}
${if(sIs_srcdeal == '2',if(len(sDeal) == 0,"","and deal_code IN ('"+ sDeal+"')"),if(len(sDeal) == 0,"","and src_deal_code IN ('"+ sDeal +"')"))}
-- 产品线
${if(len(sPl) == 0,"","and pl_name IN ('"+ sPl+"')")}
-- 品项
@ -274,7 +274,7 @@ FROM
-- 市
${if(len(sCity) == 0,"","and city_name IN ('"+ sCity+"')")}
-- 经销商
${if(len(sDeal) == 0,"","and deal_code IN ('"+sDeal+"')")}
${if(sIs_srcdeal == '2',if(len(sDeal) == 0,"","and deal_code IN ('"+ sDeal+"')"),if(len(sDeal) == 0,"","and src_deal_code IN ('"+ sDeal +"')"))}
-- 产品线
${if(len(sPl) == 0,"","and pl_name IN ('"+ sPl+"')")}
-- 品项
@ -294,4 +294,26 @@ FROM
,deal_name -- 经销商名称
,src_deal_name -- 子经销商名称
)T1
${if(len(sDim)>0," GROUP BY " + sDim ," ")}
${if(len(sDim)>0," GROUP BY " + sDim ," ")}
-- ======================================
-- 数据更新时间
-- ======================================
-- 存在多个表,取表最近的更新时间
SELECT
CONCAT('数据更新日期:',LEFT(MAX(T.update_time),19)) AS update_time
FROM
(
SELECT MAX(update_time) AS update_time FROM dwr.fact_sal_order -- dm.v_ag_sal_order -- 销售订单视图主表
UNION ALL
SELECT MAX(update_time) AS update_time FROM dwr.fact_sal_contract -- dm.v_ag_sal_contract -- 合同表 产品+合同ID
UNION ALL
SELECT MAX(update_time) AS update_time FROM dwr.fact_sal_collection -- dm.v_ag_sal_collection -- 销售回款
UNION ALL
SELECT MAX(update_time) AS update_time FROM dwr.fact_sal_deliver -- dm.v_ag_sal_deliver -- 销售发货
UNION ALL
SELECT MAX(update_time) AS update_time FROM dwr.fact_sal_dealer_stock -- dm.v_ag_sal_deal_stock -- 实物库存
)T

View File

@ -64,9 +64,9 @@ from
SELECT
*
FROM dm.dm_sal_indicator_day
WHERE to_char(stat_date,'yyyy') = '${sYear}' -- 年度
AND indi_type = '${sIndi}' -- 指标类型
${if(len(sMonth) == 0,"","and to_char(stat_date,'mm') IN ('"+sMonth+"')")}
WHERE stat_date >= '${CONCATENATE(sStart_mon,"-01 00:00:00")}'
AND stat_date <= '${CONCATENATE(ENDOFMONTH(CONCATENATE(sStart_mon,"-01"))," 00:00:00")}'
${if(len(sIndex) == 0,"","and indi_type IN ('"+sIndex+"')")}
-- 事业部
${if(len(sBu) == 0,"","and bu_code IN ('"+sBu+"')")}
-- 大区
@ -74,11 +74,11 @@ from
-- 办事处
${if(len(sOffice) == 0,"","and office_code IN ('"+ sOffice+"')")}
-- 城市单元
${if(len(sCityUnit) == 0,"","and city_unit_code IN ('"+ sCityUnit+"')")}
${if(len(sCu) == 0,"","and city_unit_code IN ('"+sCu+"')")}
-- 产品
${if(len(sProduct) == 0,"","and product_code IN ('"+ sProduct +"')")}
-- 子主经销商
${if(sDeal == 1,if(len(sDealName) == 0,"","and deal_code IN ('"+ sDealName+"')"),if(len(sDealName) == 0,"","and src_deal_code IN ('"+ sDealName +"')"))}
${if(sIs_srcdeal == '2',if(len(sDeal) == 0,"","and deal_code IN ('"+ sDeal+"')"),if(len(sDeal) == 0,"","and src_deal_code IN ('"+ sDeal +"')"))}
)a
left join dwr.dim_product p on a.product_code=p.product_code
left join dwr.dim_department dmd on a.city_unit_code=dmd.dept_code
@ -91,7 +91,7 @@ left join dwr.dim_area cit on a.city_code=cit.town_code
where 1 = 1
-- 产品线
${if(len(sPl) == 0,"","and p.pl_code IN ('"+ sPl+"')")}
${if(len(sPl_name) == 0,"","and p.pl_name IN ('"+ sPl_name +"')")}
group by to_char(a.stat_date,'yyyy'),
@ -126,4 +126,8 @@ group by to_char(a.stat_date,'yyyy'),
p.bu_code,
d.dept_name,
p.spec,
p.aroma_type
p.aroma_type
SELECT CONCAT('数据更新日期:',LEFT(MAX(update_time),19)) AS update_time FROM dm.dm_sal_indicator_day