From 5d1b61cce90c1c4df5978268ae3aecf77a19d3dd Mon Sep 17 00:00:00 2001 From: yangkunan Date: Fri, 29 Nov 2024 18:04:02 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E5=85=B3=E9=94=AE=E6=8C=87?= =?UTF-8?q?=E6=A0=87=E6=97=B6=E9=97=B4=E5=8F=82=E6=95=B0=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../销售主题/报表/销售业绩/产品订单事业部.sql | 119 ++++++++ .../销售主题/报表/销售业绩/品项订单事业部.sql | 93 ++++++ FineReport/销售主题/报表/首页.sql | 264 +++++++++++------- 3 files changed, 372 insertions(+), 104 deletions(-) create mode 100644 FineReport/销售主题/报表/销售业绩/产品订单事业部.sql create mode 100644 FineReport/销售主题/报表/销售业绩/品项订单事业部.sql diff --git a/FineReport/销售主题/报表/销售业绩/产品订单事业部.sql b/FineReport/销售主题/报表/销售业绩/产品订单事业部.sql new file mode 100644 index 0000000..ab5e9e9 --- /dev/null +++ b/FineReport/销售主题/报表/销售业绩/产品订单事业部.sql @@ -0,0 +1,119 @@ +-- ====================================== +-- 所属报表:品项主要指标达成 +-- ====================================== + + +WITH data_1 AS ( + SELECT + t2.pl_name AS "产品线", + TO_CHAR( t1.stat_date, 'YYYY' ) AS "年", + TO_CHAR( t1.stat_date, 'YYYY-MM' ) AS "年月", + TO_CHAR( t1.stat_date, 'Q' ) AS "季", + TO_CHAR( t1.stat_date, 'YYYY-MM-DD' ) AS "日", + t2.pi_name AS "品项", + t2.pr_name AS "产品系列", + t2.product_code AS "产品编码", + t2.product_name AS "产品名称", + t2.spec AS "规格", + t2.pack_base_num AS "转换率", + SUM(CASE WHEN t1.indi_type IN ('发货','电商订单','费用发货') THEN ${SWITCH(sLvl,0,'t1.amt_bu',1,'t1.amt_region',2,'t1.amt_office',3,'t1.amt_city_unit')} ELSE 0 END) AS "发货", + SUM(CASE WHEN t1.indi_type IN ('出货','电商订单') THEN ${SWITCH(sLvl,0,'t1.amt_bu',1,'t1.amt_region',2,'t1.amt_office',3,'t1.amt_city_unit')} ELSE 0 END) AS "出货", + SUM(CASE WHEN t1.indi_type = '合同' THEN ${SWITCH(sLvl,0,'t1.amt_bu',1,'t1.amt_region',2,'t1.amt_office',3,'t1.amt_city_unit')} ELSE 0 END) AS "合同", + SUM(CASE WHEN t1.indi_type = '实物库存' THEN ${SWITCH(sLvl,0,'t1.amt_bu',1,'t1.amt_region',2,'t1.amt_office',3,'t1.amt_city_unit')} ELSE 0 END) AS "实物库存", + SUM(CASE WHEN t1.indi_type = '在途库存' THEN ${SWITCH(sLvl,0,'t1.amt_bu',1,'t1.amt_region',2,'t1.amt_office',3,'t1.amt_city_unit')} ELSE 0 END) AS "在途库存", + SUM(CASE WHEN t1.indi_type = '未发货' THEN ${SWITCH(sLvl,0,'t1.amt_bu',1,'t1.amt_region',2,'t1.amt_office',3,'t1.amt_city_unit')} ELSE 0 END) AS "未发货", + SUM(CASE WHEN t1.indi_type IN('订单','电商订单','费用订单') THEN ${SWITCH(sLvl,0,'t1.amt_bu',1,'t1.amt_region',2,'t1.amt_office',3,'t1.amt_city_unit')} ELSE 0 END) AS "订单" + FROM + dm.dm_sal_indicator_day t1 + LEFT JOIN dwr.dim_product t2 ON t1.product_code = t2.product_code + WHERE + t1.indi_type IN ('发货','电商订单','费用发货','出货','合同','实物库存','在途库存','未发货','订单','费用订单') + AND t1.stat_date BETWEEN '${FORMAT(YEARDELTA(sEnd_mon,-1),"yyyy-01-01")}' AND '${sEnd_mon}' + AND EXISTS ( + SELECT + 1 + FROM + dm.dm_bi_user_permisson + WHERE + bi_user = '${fine_username}' + AND per_model IN ('all','sal') + AND ( + is_all = 1 + OR per_code = t1.bu_code + OR per_code = t1.region_code + OR per_code = t1.office_code + OR per_code = t1.city_unit_code + ) + ) + ${IF(LEN(sBu)==0,"","AND t1.bu_code IN ('"+sBu+"')")} + ${IF(LEN(sRegion)==0,"","AND t1.region_code IN ('"+sRegion+"')")} + ${IF(LEN(sOffice)==0,"","AND t1.office_code IN ('"+sOffice+"')")} + ${IF(LEN(sCu)==0,"","AND t1.city_unit_code IN ('"+sCu+"')")} + ${IF(LEN(sProvince)==0,"","AND t1.province_name IN ('"+sProvince+"')")} + ${IF(LEN(sProd)==0,"","AND t1.product_code IN ('"+sProd+"')")} + ${IF(LEN(sPi_name)==0,"","AND t2.pi_name IN ('"+sPi_name+"')")} + GROUP BY + "产品线", + "年", + "年月", + "季", + "日", + "品项", + "产品系列", + "产品编码", + "产品名称", + "规格", + "转换率" +) + +SELECT + "产品线", + "品项", + "产品系列", + "产品编码", + "产品名称", + "规格", + "转换率", + SUM(CASE WHEN "年" = '${YEAR(sEnd_mon)}' AND "日" <= '${sEnd_mon}' THEN "发货" ELSE 0 END) / 10000 AS "今年累计_发货", + SUM(CASE WHEN "年月" <= '${FORMAT(YEARDELTA(sEnd_mon,-1),"yyyy-MM")}' THEN "发货" ELSE 0 END) / 10000 AS "去年同期_发货", + SUM(CASE WHEN "年" = '${YEAR(sEnd_mon)}' AND "季" = QUARTER(DATE('${sEnd_mon}')) AND "日" <= '${sEnd_mon}' THEN "发货" ELSE 0 END) / 10000 AS "本季累计_发货", + SUM(CASE WHEN "年月" = '${FORMAT(sEnd_mon,"yyyy-MM")}' AND "日" <= '${sEnd_mon}' THEN "发货" ELSE 0 END) / 10000 AS "今年当月累计_发货", + + SUM(CASE WHEN "年" = '${YEAR(sEnd_mon)}' AND "日" <= '${sEnd_mon}' THEN "订单" ELSE 0 END) / 10000 AS "今年累计_订单", + SUM(CASE WHEN "年月" <= '${FORMAT(YEARDELTA(sEnd_mon,-1),"yyyy-MM")}' THEN "订单" ELSE 0 END) / 10000 AS "去年同期_订单", + SUM(CASE WHEN "年" = '${YEAR(sEnd_mon)}' AND "季" = QUARTER(DATE('${sEnd_mon}')) AND "日" <= '${sEnd_mon}' THEN "订单" ELSE 0 END) / 10000 AS "本季累计_订单", + SUM(CASE WHEN "年月" = '${FORMAT(sEnd_mon,"yyyy-MM")}' AND "日" <= '${sEnd_mon}' THEN "订单" ELSE 0 END) / 10000 AS "今年当月累计_订单", + + SUM(CASE WHEN "年" = '${YEAR(sEnd_mon)}' AND "日" <= '${sEnd_mon}' THEN "出货" ELSE 0 END) / 10000 AS "今年累计_出货", + SUM(CASE WHEN "年月" <= '${FORMAT(YEARDELTA(sEnd_mon,-1),"yyyy-MM")}' THEN "出货" ELSE 0 END) / 10000 AS "去年同期_出货", + SUM(CASE WHEN "年" = '${YEAR(sEnd_mon)}' AND "季" = QUARTER(DATE('${sEnd_mon}')) AND "日" <= '${sEnd_mon}' THEN "出货" ELSE 0 END) / 10000 AS "本季累计_出货", + SUM(CASE WHEN "年月" = '${FORMAT(sEnd_mon,"yyyy-MM")}' AND "日" <= '${sEnd_mon}' THEN "出货" ELSE 0 END) / 10000 AS "今年当月累计_出货", + + SUM(CASE WHEN "年" = '${YEAR(sEnd_mon)}' THEN "合同" ELSE 0 END) / 10000 AS "今年累计_合同", + SUM(CASE WHEN "年月" = '${FORMAT(sEnd_mon,"yyyy-MM")}' THEN "实物库存" ELSE 0 END) / 10000 AS "当月末经销商库存_实物库存", + SUM(CASE WHEN "年月" = '${FORMAT(sEnd_mon,"yyyy-MM")}' THEN "在途库存" ELSE 0 END) / 10000 AS "当月末经销商库存_在途", + SUM(CASE WHEN "年月" = '${FORMAT(sEnd_mon,"yyyy-MM")}' THEN "未发货" ELSE 0 END) / 10000 AS "当月末经销商库存_未发货" + + + + + +FROM + data_1 + +WHERE + "产品线" IS NOT NULL + AND "品项" IS NOT NULL +GROUP BY + "产品线", + "品项", + "产品系列", + "产品编码", + "产品名称", + "规格", + "转换率" +ORDER BY + "产品线", + "品项", + "产品系列", + "产品编码" \ No newline at end of file diff --git a/FineReport/销售主题/报表/销售业绩/品项订单事业部.sql b/FineReport/销售主题/报表/销售业绩/品项订单事业部.sql new file mode 100644 index 0000000..0aac7d7 --- /dev/null +++ b/FineReport/销售主题/报表/销售业绩/品项订单事业部.sql @@ -0,0 +1,93 @@ +-- ====================================== +-- 所属报表:品项主要指标达成 +-- ====================================== + +WITH data_1 AS ( + SELECT + t2.pl_name AS "产品线", + TO_CHAR( t1.stat_date, 'YYYY' ) AS "年", + TO_CHAR( t1.stat_date, 'YYYY-MM' ) AS "年月", + TO_CHAR( t1.stat_date, 'Q' ) AS "季", + TO_CHAR( t1.stat_date, 'YYYY-MM-DD' ) AS "日", + t2.pi_name AS "品项", + SUM(CASE WHEN t1.indi_type IN ('发货','电商订单','费用发货') THEN ${SWITCH(sLvl,0,'t1.amt_bu',1,'t1.amt_region',2,'t1.amt_office',3,'t1.amt_city_unit')} ELSE 0 END) AS "发货", + SUM(CASE WHEN t1.indi_type IN ('出货','电商订单') THEN ${SWITCH(sLvl,0,'t1.amt_bu',1,'t1.amt_region',2,'t1.amt_office',3,'t1.amt_city_unit')} ELSE 0 END) AS "出货", + SUM(CASE WHEN t1.indi_type = '合同' THEN ${SWITCH(sLvl,0,'t1.amt_bu',1,'t1.amt_region',2,'t1.amt_office',3,'t1.amt_city_unit')} ELSE 0 END) AS "合同", + SUM(CASE WHEN t1.indi_type = '实物库存' THEN ${SWITCH(sLvl,0,'t1.amt_bu',1,'t1.amt_region',2,'t1.amt_office',3,'t1.amt_city_unit')} ELSE 0 END) AS "实物库存", + SUM(CASE WHEN t1.indi_type = '在途库存' THEN ${SWITCH(sLvl,0,'t1.amt_bu',1,'t1.amt_region',2,'t1.amt_office',3,'t1.amt_city_unit')} ELSE 0 END) AS "在途库存", + SUM(CASE WHEN t1.indi_type = '未发货' THEN ${SWITCH(sLvl,0,'t1.amt_bu',1,'t1.amt_region',2,'t1.amt_office',3,'t1.amt_city_unit')} ELSE 0 END) AS "未发货", + SUM(CASE WHEN t1.indi_type IN('订单','电商订单','费用订单') THEN ${SWITCH(sLvl,0,'t1.amt_bu',1,'t1.amt_region',2,'t1.amt_office',3,'t1.amt_city_unit')} ELSE 0 END) AS "订单" + + FROM + dm.dm_sal_indicator_day t1 + LEFT JOIN dwr.dim_product t2 ON t1.product_code = t2.product_code + WHERE + t1.indi_type IN ('发货','电商订单','费用发货','出货','合同','实物库存','在途库存','未发货','订单','费用订单') + AND t1.stat_date BETWEEN '${FORMAT(YEARDELTA(sEnd_mon,-1),"yyyy-01-01")}' AND '${sEnd_mon}' + AND EXISTS ( + SELECT + 1 + FROM + dm.dm_bi_user_permisson + WHERE + bi_user = '${fine_username}' + AND per_model IN ('all','sal') + AND ( + is_all = 1 + OR per_code = t1.bu_code + OR per_code = t1.region_code + OR per_code = t1.office_code + OR per_code = t1.city_unit_code + ) + ) + ${IF(LEN(sBu)==0,"","AND t1.bu_code IN ('"+sBu+"')")} + ${IF(LEN(sRegion)==0,"","AND t1.region_code IN ('"+sRegion+"')")} + ${IF(LEN(sOffice)==0,"","AND t1.office_code IN ('"+sOffice+"')")} + ${IF(LEN(sCu)==0,"","AND t1.city_unit_code IN ('"+sCu+"')")} + ${IF(LEN(sProvince)==0,"","AND t1.province_name IN ('"+sProvince+"')")} + ${IF(LEN(sCp_region)==0,"","AND t1.cp_region_code IN ('"+sCp_region+"')")} + GROUP BY + "产品线", + "年", + "年月", + "季", + "日", + "品项" + +) + +SELECT + "产品线", + "品项", + SUM(CASE WHEN "年" = '${YEAR(sEnd_mon)}' AND "日" <= '${sEnd_mon}' THEN "发货" ELSE 0 END) / 10000 AS "今年累计_发货", + SUM(CASE WHEN "年月" <= '${FORMAT(YEARDELTA(sEnd_mon,-1),"yyyy-MM")}' THEN "发货" ELSE 0 END) / 10000 AS "去年同期_发货", + SUM(CASE WHEN "年" = '${YEAR(sEnd_mon)}' AND "季" = QUARTER(DATE('${sEnd_mon}')) AND "日" <= '${sEnd_mon}' THEN "发货" ELSE 0 END) / 10000 AS "本季累计_发货", + SUM(CASE WHEN "年月" = '${FORMAT(sEnd_mon,"yyyy-MM")}' AND "日" <= '${sEnd_mon}' THEN "发货" ELSE 0 END) / 10000 AS "今年当月累计_发货", + + SUM(CASE WHEN "年" = '${YEAR(sEnd_mon)}' AND "日" <= '${sEnd_mon}' THEN "订单" ELSE 0 END) / 10000 AS "今年累计_订单", + SUM(CASE WHEN "年月" <= '${FORMAT(YEARDELTA(sEnd_mon,-1),"yyyy-MM")}' THEN "订单" ELSE 0 END) / 10000 AS "去年同期_订单", + SUM(CASE WHEN "年" = '${YEAR(sEnd_mon)}' AND "季" = QUARTER(DATE('${sEnd_mon}')) AND "日" <= '${sEnd_mon}' THEN "订单" ELSE 0 END) / 10000 AS "本季累计_订单", + SUM(CASE WHEN "年月" = '${FORMAT(sEnd_mon,"yyyy-MM")}' AND "日" <= '${sEnd_mon}' THEN "订单" ELSE 0 END) / 10000 AS "今年当月累计_订单", + + + SUM(CASE WHEN "年" = '${YEAR(sEnd_mon)}' AND "日" <= '${sEnd_mon}' THEN "出货" ELSE 0 END) / 10000 AS "今年累计_出货", + SUM(CASE WHEN "年月" <= '${FORMAT(YEARDELTA(sEnd_mon,-1),"yyyy-MM")}' THEN "出货" ELSE 0 END) / 10000 AS "去年同期_出货", + SUM(CASE WHEN "年" = '${YEAR(sEnd_mon)}' AND "季" = QUARTER(DATE('${sEnd_mon}')) AND "日" <= '${sEnd_mon}' THEN "出货" ELSE 0 END) / 10000 AS "本季累计_出货", + SUM(CASE WHEN "年月" = '${FORMAT(sEnd_mon,"yyyy-MM")}' AND "日" <= '${sEnd_mon}' THEN "出货" ELSE 0 END) / 10000 AS "今年当月累计_出货", + + SUM(CASE WHEN "年" = '${YEAR(sEnd_mon)}' THEN "合同" ELSE 0 END) / 10000 AS "今年累计_合同", + SUM(CASE WHEN "年月" = '${FORMAT(sEnd_mon,"yyyy-MM")}' THEN "实物库存" ELSE 0 END) / 10000 AS "当月末经销商库存_实物库存", + SUM(CASE WHEN "年月" = '${FORMAT(sEnd_mon,"yyyy-MM")}' THEN "在途库存" ELSE 0 END) / 10000 AS "当月末经销商库存_在途", + SUM(CASE WHEN "年月" = '${FORMAT(sEnd_mon,"yyyy-MM")}' THEN "未发货" ELSE 0 END) / 10000 AS "当月末经销商库存_未发货" + +FROM + data_1 +WHERE + "产品线" IS NOT NULL + AND "品项" IS NOT NULL +GROUP BY + "产品线", + "品项" +ORDER BY + "产品线", + "品项" \ No newline at end of file diff --git a/FineReport/销售主题/报表/首页.sql b/FineReport/销售主题/报表/首页.sql index 4b415be..a9a8d82 100644 --- a/FineReport/销售主题/报表/首页.sql +++ b/FineReport/销售主题/报表/首页.sql @@ -96,6 +96,7 @@ where exists ( -- OR per_code = a.city_unit_code -- 城市单元 ) ) + AND ct_status = '已终审' ${IF(len(sStart_date) > 0,"AND ct_year ='"+ FORMAT(sStart_date,'yyyy') +"'","")} -- 年 -- ${IF(sPeriod=1,"AND ct_year ='"+ FORMAT(sStart_date,'yyyy') +"'","")} @@ -130,7 +131,7 @@ where exists ( OR per_code = a.city_unit_code -- 城市单元 ) ) - + AND ct_status = '已终审' ${IF(len(sStart_date) > 0,"AND ct_year = '" + left(yeardelta(sStart_date,-1),4) + "'","")} -- 去年 @@ -212,16 +213,19 @@ AND exists ( ) -- 年 ${IF(sPeriod=1,"AND to_char(stat_date,'yyyy') ='"+ FORMAT(sStart_date,'yyyy') +"'","")} +${IF(sPeriod=1,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ FORMAT(sStart_date,'yyyy-MM-dd') +"'","")} -- 季 ${IF(sPeriod=2,"AND CONCAT(to_char(stat_date,'yyyy'),EXTRACT(QUARTER FROM stat_date)) ='"+ CONCATENATE(left(sStart_date,4),roundup(month(sStart_date)/3)) +"'","")} +${IF(sPeriod=2,"AND to_char(stat_date,'yyyy-MM-dd') <= '"+ FORMAT(sStart_date,'yyyy-MM-dd') +"'","")} + -- ${IF(sPeriod=2,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")} -- 月 ${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM') ='"+ FORMAT(sStart_date,'yyyy-MM') +"'","")} +${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM-dd') <= '"+ FORMAT(sStart_date,'yyyy-MM-dd') +"'","")} -- ${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")} -- 日 ${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') ='"+ sStart_date +"'","")} -- ${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")} - UNION ALL select '同期' time_type @@ -247,12 +251,16 @@ where (indi_type='回款' OR indi_type='电商订单') -- 去年 ${IF(sPeriod=1,"AND to_char(stat_date,'yyyy') = '" + left(yeardelta(sStart_date,-1),4) + "'","")} +${IF(sPeriod=1,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ FORMAT(yeardelta(sStart_date,-1),'yyyy-MM-dd') +"'","")} + -- 去年同季 ${IF(sPeriod=2,"AND CONCAT(to_char(stat_date,'yyyy'),EXTRACT(QUARTER FROM stat_date)) ='"+ CONCATENATE(left(YEARDELTA(sStart_date,-1),4),roundup(month(YEARDELTA(sStart_date,-1))/3)) +"'","")} +${IF(sPeriod=2,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ FORMAT(yeardelta(sStart_date,-1),'yyyy-MM-dd') +"'","")} -- ${IF(sPeriod=2,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ yeardelta(sEnd_date,-1) +"'","")} -- 去年同月 ${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM') ='"+ FORMAT(yeardelta(sStart_date,-1),'yyyy-MM') +"'","")} +${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ FORMAT(yeardelta(sStart_date,-1),'yyyy-MM-dd') +"'","")} -- ${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ yeardelta(sEnd_date,-1) +"'","")} -- 去年同日 ${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') ='"+ yeardelta(sStart_date,-1) +"'","")} @@ -324,11 +332,18 @@ where (indi_type='出货' OR indi_type='电商订单') ) -- 年 ${IF(sPeriod=1,"AND to_char(stat_date,'yyyy') ='"+ FORMAT(sStart_date,'yyyy') +"'","")} + ${IF(sPeriod=1,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ FORMAT(sStart_date,'yyyy-MM-dd') +"'","")} + -- 季 ${IF(sPeriod=2,"AND CONCAT(to_char(stat_date,'yyyy'),EXTRACT(QUARTER FROM stat_date)) ='"+ CONCATENATE(left(sStart_date,4),roundup(month(sStart_date)/3)) +"'","")} + ${IF(sPeriod=2,"AND to_char(stat_date,'yyyy-MM-dd') <= '"+ FORMAT(sStart_date,'yyyy-MM-dd') +"'","")} + + -- ${IF(sPeriod=2,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")} -- 月 ${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM') ='"+ FORMAT(sStart_date,'yyyy-MM') +"'","")} + ${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM-dd') <= '"+ FORMAT(sStart_date,'yyyy-MM-dd') +"'","")} + -- ${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")} -- 日 ${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') ='"+ sStart_date +"'","")} @@ -358,12 +373,18 @@ where (indi_type='出货' OR indi_type='电商订单') ) -- 去年 - ${IF(sPeriod=1,"AND to_char(stat_date,'yyyy') = '" + left(yeardelta(sStart_date,-1),4) + "'","")} +${IF(sPeriod=1,"AND to_char(stat_date,'yyyy') = '" + left(yeardelta(sStart_date,-1),4) + "'","")} +${IF(sPeriod=1,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ FORMAT(yeardelta(sStart_date,-1),'yyyy-MM-dd') +"'","")} + -- 去年同季 - ${IF(sPeriod=2,"AND CONCAT(to_char(stat_date,'yyyy'),EXTRACT(QUARTER FROM stat_date)) ='"+ CONCATENATE(left(YEARDELTA(sStart_date,-1),4),roundup(month(YEARDELTA(sStart_date,-1))/3)) +"'","")} +${IF(sPeriod=2,"AND CONCAT(to_char(stat_date,'yyyy'),EXTRACT(QUARTER FROM stat_date)) ='"+ CONCATENATE(left(YEARDELTA(sStart_date,-1),4),roundup(month(YEARDELTA(sStart_date,-1))/3)) +"'","")} +${IF(sPeriod=2,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ FORMAT(yeardelta(sStart_date,-1),'yyyy-MM-dd') +"'","")} + -- ${IF(sPeriod=2,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ yeardelta(sEnd_date,-1) +"'","")} -- 去年同月 ${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM') ='"+ FORMAT(yeardelta(sStart_date,-1),'yyyy-MM') +"'","")} + ${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ FORMAT(yeardelta(sStart_date,-1),'yyyy-MM-dd') +"'","")} + -- ${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ yeardelta(sEnd_date,-1) +"'","")} -- 去年同日 ${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') ='"+ yeardelta(sStart_date,-1) +"'","")} @@ -438,11 +459,17 @@ where (indi_type='发货' OR indi_type='费用发货') ) -- 年 ${IF(sPeriod=1,"AND to_char(stat_date,'yyyy') ='"+ FORMAT(sStart_date,'yyyy') +"'","")} + ${IF(sPeriod=1,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ FORMAT(sStart_date,'yyyy-MM-dd') +"'","")} + -- 季 ${IF(sPeriod=2,"AND CONCAT(to_char(stat_date,'yyyy'),EXTRACT(QUARTER FROM stat_date)) ='"+ CONCATENATE(left(sStart_date,4),roundup(month(sStart_date)/3)) +"'","")} + ${IF(sPeriod=2,"AND to_char(stat_date,'yyyy-MM-dd') <= '"+ FORMAT(sStart_date,'yyyy-MM-dd') +"'","")} + -- ${IF(sPeriod=2,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")} -- 月 ${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM') ='"+ FORMAT(sStart_date,'yyyy-MM') +"'","")} + ${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM-dd') <= '"+ FORMAT(sStart_date,'yyyy-MM-dd') +"'","")} + -- ${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sEnd_date +"'","")} -- 日 ${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') ='"+ sStart_date +"'","")} @@ -472,11 +499,17 @@ where (indi_type='发货' OR indi_type='费用发货') -- 去年 ${IF(sPeriod=1,"AND to_char(stat_date,'yyyy') = '" + left(yeardelta(sStart_date,-1),4) + "'","")} + ${IF(sPeriod=1,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ FORMAT(yeardelta(sStart_date,-1),'yyyy-MM-dd') +"'","")} + -- 去年同季 ${IF(sPeriod=2,"AND CONCAT(to_char(stat_date,'yyyy'),EXTRACT(QUARTER FROM stat_date)) ='"+ CONCATENATE(left(YEARDELTA(sStart_date,-1),4),roundup(month(YEARDELTA(sStart_date,-1))/3)) +"'","")} + ${IF(sPeriod=2,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ FORMAT(yeardelta(sStart_date,-1),'yyyy-MM-dd') +"'","")} + -- ${IF(sPeriod=2,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ yeardelta(sEnd_date,-1) +"'","")} -- 去年同月 ${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM') ='"+ FORMAT(yeardelta(sStart_date,-1),'yyyy-MM') +"'","")} + ${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ FORMAT(yeardelta(sStart_date,-1),'yyyy-MM-dd') +"'","")} + -- ${IF(sPeriod=3,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ yeardelta(sEnd_date,-1) +"'","")} -- 去年同日 ${IF(sPeriod=4,"AND to_char(stat_date,'yyyy-MM-dd') ='"+ yeardelta(sStart_date,-1) +"'","")} @@ -527,22 +560,21 @@ where ${switch(sPeriod -- ====================================== - -- 资金计划与执行 select -'当期' AS time_type -,'收入' AS fee_type -- 收支方向 收入/支出 -,SUM(CASE WHEN trade_direction = '收入' THEN amt ELSE 0 END) / 10000 AS amt + '当期' AS time_type + ,'收入' AS fee_type -- 收支方向 收入/支出 + ,SUM(CASE WHEN trade_direction = '收入' THEN amt ELSE 0 END) / 10000 AS amt from dm.dm_fim_fud_indicator a where corp_code not in ('0101','0103','0102') -AND trade_direction = '收入' -AND indi_type = '执行' -AND plan_item_name NOT IN ('内部调拨收入','取得贷款') -AND owner_bank_account <> '22195101040012008' + AND trade_direction = '收入' + AND indi_type = '执行' + AND plan_item_name NOT IN ('内部调拨收入','取得贷款') + AND owner_bank_account <> '22195101040012008' -- 权限控制 -AND exists ( + AND exists ( select - 1 + 1 from dm.dm_bi_user_permisson where @@ -557,17 +589,21 @@ AND exists ( ) ) -- 年 - ${IF(sPeriod_fin=1,"AND to_char(stat_date,'yyyy') ='"+ FORMAT(sStart_date_fin,'yyyy') +"'","")} + ${IF(sPeriod_fin=1,"AND to_char(stat_date,'yyyy') ='"+ FORMAT(sStart_mon,'yyyy') +"'","")} + ${IF(sPeriod_fin=1,"AND to_char(stat_date,'yyyy-MM') <= '"+ FORMAT(sStart_mon,'yyyy-MM') +"'","")} + -- 月 - ${IF(sPeriod_fin=2,"AND to_char(stat_date,'yyyy-MM') = '"+ FORMAT(sStart_date_fin,'yyyy-MM') +"'","")} + ${IF(sPeriod_fin=2,"AND to_char(stat_date,'yyyy-MM') = '"+ FORMAT(sStart_mon,'yyyy-MM') +"'","")} +-- ${IF(sPeriod_fin=2,"AND to_char(stat_date,'yyyy-MM') <= '"+ FORMAT(sStart_date_fin,'yyyy-MM-dd') +"'","")} + -- 日 - ${IF(sPeriod_fin=3,"AND to_char(stat_date,'yyyy-MM-dd') >= '"+ sStart_date_fin +"'","")} - ${IF(sPeriod_fin=4,"AND to_char(stat_date,'yyyy-MM-dd') <= '"+ sStart_date_fin +"'","")} +-- ${IF(sPeriod_fin=3,"AND to_char(stat_date,'yyyy-MM-dd') >= '"+ FORMAT(sStart_date_fin,'yyyy-MM-dd') +"'","")} +-- ${IF(sPeriod_fin=3,"AND to_char(stat_date,'yyyy-MM-dd') <= '"+ FORMAT(sStart_date_fin,'yyyy-MM-dd') +"'","")} UNION ALL select -'当期' AS time_type -,'支出' AS fee_type -- 收支方向 收入/支出 -,SUM(CASE WHEN trade_direction = '支出' THEN amt ELSE 0 END) / 10000 AS amt + '当期' AS time_type + ,'支出' AS fee_type -- 收支方向 收入/支出 + ,SUM(CASE WHEN trade_direction = '支出' THEN amt ELSE 0 END) / 10000 AS amt from dm.dm_fim_fud_indicator a where corp_code not in ('0101','0103','0102') AND trade_direction = '支出' @@ -577,7 +613,7 @@ where corp_code not in ('0101','0103','0102') -- 权限控制 AND exists ( select - 1 + 1 from dm.dm_bi_user_permisson where @@ -593,32 +629,37 @@ where corp_code not in ('0101','0103','0102') ) -- 年 - ${IF(sPeriod_fin=1,"AND to_char(stat_date,'yyyy') ='"+ FORMAT(sStart_date_fin,'yyyy') +"'","")} + ${IF(sPeriod_fin=1,"AND to_char(stat_date,'yyyy') ='"+ FORMAT(sStart_mon,'yyyy') +"'","")} + ${IF(sPeriod_fin=1,"AND to_char(stat_date,'yyyy-MM') <='"+ FORMAT(sStart_mon,'yyyy-MM') +"'","")} + -- 月 - ${IF(sPeriod_fin=2,"AND to_char(stat_date,'yyyy-MM') ='"+ FORMAT(sStart_date_fin,'yyyy-MM') +"'","")} + ${IF(sPeriod_fin=2,"AND to_char(stat_date,'yyyy-MM') ='"+ FORMAT(sStart_mon,'yyyy-MM') +"'","")} +-- ${IF(sPeriod_fin=2,"AND to_char(stat_date,'yyyy-MM-dd') <= '"+ FORMAT(sStart_date_fin,'yyyy-MM-dd') +"'","")} + -- 日 - ${IF(sPeriod_fin=3,"AND to_char(stat_date,'yyyy-MM-dd') >='"+ sStart_date_fin +"'","")} - ${IF(sPeriod_fin=4,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sStart_date_fin +"'","")} +-- ${IF(sPeriod_fin=3,"AND to_char(stat_date,'yyyy-MM-dd') >='"+ FORMAT(sStart_date_fin,'yyyy-MM-dd') +"'","")} +-- ${IF(sPeriod_fin=3,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ FORMAT(sStart_date_fin,'yyyy-MM-dd') +"'","")} UNION ALL -- 月初资金余额要取上月的月初的,年初要取上年末12月份的 select -'当期' AS time_type -,'余额' AS fee_type -,sum(amt) / 10000 AS AMT + '当期' AS time_type + ,'余额' AS fee_type + ,sum(amt) / 10000 AS AMT from dm.dm_fim_fud_balance a where corp_code not in ('0101','0103','0102') -AND owner_bank_account NOT IN ('20351059900100000512291' + AND owner_bank_account NOT IN ('20351059900100000512291' ,'22195101040012008' ,'信用证保证金' ,'22195162750000012' ,'22195162650000017' ,'22195162350000014' ,'22195162050000015' - ,'951018033000447470') + ,'951018033000447470' + ,'22195162950000025') -- 权限控制 AND exists ( select - 1 + 1 from dm.dm_bi_user_permisson where @@ -633,12 +674,16 @@ AND owner_bank_account NOT IN ('20351059900100000512291' ) ) -- 年 - ${IF(sPeriod_fin=1,"AND to_char(stat_date,'yyyy') ='"+ FORMAT(sStart_date_fin,'yyyy') +"'","")} + ${IF(sPeriod_fin=1,"AND to_char(stat_date,'yyyy') ='"+ FORMAT(sStart_mon,'yyyy') +"'","")} + ${IF(sPeriod_fin=1,"AND to_char(stat_date,'yyyy-MM') <='"+ FORMAT(MONTHDELTA(sStart_mon,-1),'yyyy-MM') +"'","")} + -- 月 - ${IF(sPeriod_fin=2,"AND to_char(stat_date,'yyyy-MM') ='"+ FORMAT(MONTHDELTA(sStart_date_fin,-1),'yyyy-MM') +"'","")} + ${IF(sPeriod_fin=2,"AND to_char(stat_date,'yyyy-MM') ='"+ FORMAT(MONTHDELTA(sStart_mon,-1),'yyyy-MM') +"'","")} +-- ${IF(sPeriod_fin=2,"AND to_char(stat_date,'yyyy-MM-dd') <= '"+ FORMAT(MONTHDELTA(sStart_date_fin,-1),'yyyy-MM-dd') +"'","")} + -- 日 - ${IF(sPeriod_fin=3,"AND to_char(stat_date,'yyyy-MM-dd') >='"+ sStart_date_fin +"'","")} - ${IF(sPeriod_fin=4,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sStart_date_fin +"'","")} +-- ${IF(sPeriod_fin=3,"AND to_char(stat_date,'yyyy-MM-dd') >='"+ FORMAT(MONTHDELTA(sStart_date_fin,-1),'yyyy-MM-dd') +"'","")} +-- ${IF(sPeriod_fin=3,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ FORMAT(MONTHDELTA(sStart_date_fin,-1),'yyyy-MM-dd') +"'","")} UNION ALL -- 资金计划与执行 @@ -670,12 +715,16 @@ where corp_code not in ('0101','0103','0102') ) ) -- 上年 - ${IF(sPeriod_fin=1,"AND to_char(stat_date,'yyyy') ='"+ FORMAT(YEARDELTA(sStart_date_fin,-1),'yyyy') +"'","")} + ${IF(sPeriod_fin=1,"AND to_char(stat_date,'yyyy') ='"+ FORMAT(YEARDELTA(sStart_mon,-1),'yyyy') +"'","")} + ${IF(sPeriod_fin=1,"AND to_char(stat_date,'yyyy-MM') <='"+ FORMAT(yeardelta(sStart_mon,-1),'yyyy-MM') +"'","")} + -- 上月 - ${IF(sPeriod_fin=2,"AND to_char(stat_date,'yyyy-MM') = '"+ FORMAT(MONTHDELTA(sStart_date_fin,-1),'yyyy-MM') +"'","")} + ${IF(sPeriod_fin=2,"AND to_char(stat_date,'yyyy-MM') = '"+ FORMAT(MONTHDELTA(sStart_mon,-1),'yyyy-MM') +"'","")} +-- ${IF(sPeriod_fin=2,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ FORMAT(MONTHDELTA(sStart_date_fin,-1),'yyyy-MM-dd') +"'","")} + -- 昨日 - ${IF(sPeriod_fin=3,"AND to_char(stat_date,'yyyy-MM-dd') >= '"+ DATEDELTA(sStart_date_fin,-1) +"'","")} - ${IF(sPeriod_fin=4,"AND to_char(stat_date,'yyyy-MM-dd') <= '"+ DATEDELTA(sStart_date_fin,-1) +"'","")} +-- ${IF(sPeriod_fin=3,"AND to_char(stat_date,'yyyy-MM-dd') >= '"+ FORMAT(DATEDELTA(sStart_date_fin,-1),'yyyy-MM-dd') +"'","")} +-- ${IF(sPeriod_fin=3,"AND to_char(stat_date,'yyyy-MM-dd') <= '"+ FORMAT(DATEDELTA(sStart_date_fin,-1),'yyyy-MM-dd') +"'","")} UNION ALL select '上期' AS time_type @@ -706,12 +755,15 @@ where corp_code not in ('0101','0103','0102') ) -- 上年 - ${IF(sPeriod_fin=1,"AND to_char(stat_date,'yyyy') ='"+ FORMAT(YEARDELTA(sStart_date_fin,-1),'yyyy') +"'","")} + ${IF(sPeriod_fin=1,"AND to_char(stat_date,'yyyy') ='"+ FORMAT(YEARDELTA(sStart_mon,-1),'yyyy') +"'","")} + ${IF(sPeriod_fin=1,"AND to_char(stat_date,'yyyy-MM') <='"+ FORMAT(yeardelta(sStart_mon,-1),'yyyy-MM') +"'","")} -- 上月 - ${IF(sPeriod_fin=2,"AND to_char(stat_date,'yyyy-MM') = '"+ FORMAT(MONTHDELTA(sStart_date_fin,-1),'yyyy-MM') +"'","")} + ${IF(sPeriod_fin=2,"AND to_char(stat_date,'yyyy-MM') = '"+ FORMAT(MONTHDELTA(sStart_mon,-1),'yyyy-MM') +"'","")} +-- ${IF(sPeriod_fin=2,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ FORMAT(MONTHDELTA(sStart_date_fin,-1),'yyyy-MM-dd') +"'","")} -- 昨日 - ${IF(sPeriod_fin=3,"AND to_char(stat_date,'yyyy-MM-dd') >= '"+ DATEDELTA(sStart_date_fin,-1) +"'","")} - ${IF(sPeriod_fin=4,"AND to_char(stat_date,'yyyy-MM-dd') <= '"+ DATEDELTA(sStart_date_fin,-1) +"'","")} + +-- ${IF(sPeriod_fin=3,"AND to_char(stat_date,'yyyy-MM-dd') >= '"+ FORMAT(DATEDELTA(sStart_date_fin,-1),'yyyy-MM-dd') +"'","")} +-- ${IF(sPeriod_fin=3,"AND to_char(stat_date,'yyyy-MM-dd') <= '"+ FORMAT(DATEDELTA(sStart_date_fin,-1),'yyyy-MM-dd') +"'","")} UNION ALL -- 月初资金余额要取上月的月初的,年初要取上年末12月份的 select @@ -727,7 +779,8 @@ where corp_code not in ('0101','0103','0102') ,'22195162650000017' ,'22195162350000014' ,'22195162050000015' - ,'951018033000447470') + ,'951018033000447470' + ,'22195162950000025') -- 权限控制 AND exists ( select @@ -746,25 +799,27 @@ where corp_code not in ('0101','0103','0102') ) ) -- 上年 - ${IF(sPeriod_fin=1,"AND to_char(stat_date,'yyyy') ='"+ FORMAT(YEARDELTA(sStart_date_fin,-1),'yyyy') +"'","")} + ${IF(sPeriod_fin=1,"AND to_char(stat_date,'yyyy') ='"+ FORMAT(YEARDELTA(sStart_mon,-1),'yyyy') +"'","")} + ${IF(sPeriod_fin=1,"AND to_char(stat_date,'yyyy-MM') <='"+ FORMAT(YEARDELTA(MONTHDELTA(sStart_mon,-1),-1),'yyyy-MM') +"'","")} + -- 上月 - ${IF(sPeriod_fin=2,"AND to_char(stat_date,'yyyy-MM') ='"+ FORMAT(MONTHDELTA(sStart_date_fin,-2),'yyyy-MM') +"'","")} + ${IF(sPeriod_fin=2,"AND to_char(stat_date,'yyyy-MM') ='"+ FORMAT(MONTHDELTA(sStart_mon,-2),'yyyy-MM') +"'","")} +-- ${IF(sPeriod_fin=2,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ FORMAT(MONTHDELTA(sStart_date_fin,-2),'yyyy-MM-dd') +"'","")} + -- 昨日 - ${IF(sPeriod_fin=3,"AND to_char(stat_date,'yyyy-MM-dd') >= '"+ DATEDELTA(sStart_date_fin,-1) +"'","")} - ${IF(sPeriod_fin=4,"AND to_char(stat_date,'yyyy-MM-dd') <= '"+ DATEDELTA(sStart_date_fin,-1) +"'","")} - +-- ${IF(sPeriod_fin=3,"AND to_char(stat_date,'yyyy-MM-dd') >= '"+ FORMAT(DATEDELTA(MONTHDELTA(sStart_date_fin,-1),-1),'yyyy-MM-dd') +"'","")} +-- ${IF(sPeriod_fin=3,"AND to_char(stat_date,'yyyy-MM-dd') <= '"+ FORMAT(DATEDELTA(MONTHDELTA(sStart_date_fin,-1),-1),'yyyy-MM-dd') +"'","")} -- ====================================== -- 财务资金月度 -- ====================================== - SELECT -t.stat_date AS stat_date -,to_char(t.stat_date,'MM') as month -,CASE WHEN t.fee_type = '收入' THEN amt ELSE 0 END AS revenue_fee -- 收入 -,CASE WHEN t.fee_type = '支出' THEN amt ELSE 0 END AS expend_fee -- 支出 -,CASE WHEN t.fee_type = '余额' THEN amt ELSE 0 END AS balance_fee -- 余额 + t.stat_date AS stat_date + ,to_char(t.stat_date,'MM') as month + ,CASE WHEN t.fee_type = '收入' THEN amt ELSE 0 END AS revenue_fee -- 收入 + ,CASE WHEN t.fee_type = '支出' THEN amt ELSE 0 END AS expend_fee -- 支出 + ,CASE WHEN t.fee_type = '余额' THEN amt ELSE 0 END AS balance_fee -- 余额 FROM (SELECT stat_date , '收入' AS fee_type -- 收支方向 收入/支出 , SUM(CASE WHEN trade_direction = '收入' THEN amt ELSE 0 END) / 10000 AS amt @@ -789,7 +844,7 @@ FROM (SELECT stat_date -- OR per_code = a.city_unit_code -- 城市单元 ) ) - ${IF(len(sStart_date_fin) > 0,"AND to_char(stat_date,'yyyy') ='"+ FORMAT(sStart_date_fin,'yyyy') +"'","")} + ${IF(len(sStart_mon) > 0,"AND to_char(stat_date,'yyyy') ='"+ FORMAT(sStart_mon,'yyyy') +"'","")} -- 年 -- ${IF(sPeriod_fin=1,"AND to_char(stat_date,'yyyy') ='"+ FORMAT(sStart_date_fin,'yyyy') +"'","")} -- 月 @@ -823,7 +878,7 @@ FROM (SELECT stat_date -- OR per_code = a.city_unit_code -- 城市单元 ) ) - ${IF(len(sStart_date_fin) > 0,"AND to_char(stat_date,'yyyy') ='"+ FORMAT(sStart_date_fin,'yyyy') +"'","")} + ${IF(len(sStart_mon) > 0,"AND to_char(stat_date,'yyyy') ='"+ FORMAT(sStart_mon,'yyyy') +"'","")} -- 年 -- ${IF(sPeriod_fin=1,"AND to_char(stat_date,'yyyy') ='"+ FORMAT(sStart_date_fin,'yyyy') +"'","")} -- 月 @@ -836,61 +891,61 @@ FROM (SELECT stat_date -- 月初资金余额要取上月的月初的,年初要取上年末12月份的 SELECT - A.stat_date AS stat_date - , '余额' AS fee_type - ,SUM(B.amt) / 10000 AS AMT + A.stat_date AS stat_date + , '余额' AS fee_type + ,SUM(B.amt) AS AMT FROM - ( - SELECT - stat_date - ,stat_date - INTERVAL '1 month' AS stat_date1 - , SUM(amt) / 10000 AS AMT - FROM dm.dm_fim_fud_balance a - WHERE corp_code NOT IN ('0101', '0103', '0102') - AND owner_bank_account NOT IN - ('20351059900100000512291', '22195101040012008', '信用证保证金', '22195162750000012', '22195162650000017', - '22195162350000014', '22195162050000015', '951018033000447470') + ( + SELECT + stat_date + ,stat_date - INTERVAL '1 month' AS stat_date1 + , SUM(amt) / 10000 AS AMT + FROM dm.dm_fim_fud_balance a + WHERE corp_code NOT IN ('0101', '0103', '0102') + AND owner_bank_account NOT IN + ('20351059900100000512291', '22195101040012008', '信用证保证金', '22195162750000012', '22195162650000017', + '22195162350000014', '22195162050000015', '951018033000447470','22195162950000025') -- 权限控制 - AND EXISTS (SELECT 1 - FROM dm.dm_bi_user_permisson - WHERE bi_user = '${fine_username}' - AND per_model IN ('all', 'sal') - AND ( - is_all = 1 - OR per_code = a.corp_code -- 事业部 + AND EXISTS (SELECT 1 + FROM dm.dm_bi_user_permisson + WHERE bi_user = '${fine_username}' + AND per_model IN ('all', 'sal') + AND ( + is_all = 1 + OR per_code = a.corp_code -- 事业部 -- OR per_code = a.region_code -- 大区 -- OR per_code = a.office_code -- 办事处 -- OR per_code = a.city_unit_code -- 城市单元 - )) - GROUP BY stat_date - INTERVAL '1 month',stat_date - )A - LEFT JOIN - ( - SELECT stat_date AS stat_date + )) + GROUP BY stat_date - INTERVAL '1 month',stat_date + )A + LEFT JOIN + ( + SELECT stat_date AS stat_date - , SUM(amt) / 10000 AS AMT - FROM dm.dm_fim_fud_balance a - WHERE corp_code NOT IN ('0101', '0103', '0102') - AND owner_bank_account NOT IN - ('20351059900100000512291', '22195101040012008', '信用证保证金', '22195162750000012', '22195162650000017', - '22195162350000014', '22195162050000015', '951018033000447470') + , SUM(amt) / 10000 AS AMT + FROM dm.dm_fim_fud_balance a + WHERE corp_code NOT IN ('0101', '0103', '0102') + AND owner_bank_account NOT IN + ('20351059900100000512291', '22195101040012008', '信用证保证金', '22195162750000012', '22195162650000017', + '22195162350000014', '22195162050000015', '951018033000447470','22195162950000025') -- 权限控制 - AND EXISTS (SELECT 1 - FROM dm.dm_bi_user_permisson - WHERE bi_user = '${fine_username}' - AND per_model IN ('all', 'sal') - AND ( - is_all = 1 - OR per_code = a.corp_code -- 事业部 - )) - GROUP BY stat_date - )B - ON A.stat_date1 = B.stat_date - ${IF(len(sStart_date_fin) > 0,"AND to_char(a.stat_date,'yyyy') ='"+ FORMAT(sStart_date_fin,'yyyy') +"'","")} + AND EXISTS (SELECT 1 + FROM dm.dm_bi_user_permisson + WHERE bi_user = '${fine_username}' + AND per_model IN ('all', 'sal') + AND ( + is_all = 1 + OR per_code = a.corp_code -- 事业部 + )) + GROUP BY stat_date + )B + ON A.stat_date1 = B.stat_date + ${IF(len(sStart_mon) > 0,"AND to_char(a.stat_date,'yyyy') ='"+ FORMAT(sStart_mon,'yyyy') +"'","")} - -- 年 - -- ${IF(sPeriod_fin=1,"AND to_char(stat_date,'yyyy') ='"+ FORMAT(sStart_date_fin,'yyyy') +"'","")} + -- 年 + -- ${IF(sPeriod_fin=1,"AND to_char(stat_date,'yyyy') ='"+ FORMAT(sStart_date_fin,'yyyy') +"'","")} -- 月 -- ${IF(sPeriod_fin=2,"AND to_char(stat_date,'yyyy-MM') ='"+ FORMAT(MONTHDELTA(sStart_date_fin,-1),'yyyy-MM') +"'","")} -- 日 @@ -898,4 +953,5 @@ FROM (SELECT stat_date -- ${IF(sPeriod_fin=4,"AND to_char(stat_date,'yyyy-MM-dd') <='"+ sStart_date_fin +"'","")} group by A.stat_date )t + ${IF(len(sStart_mon) > 0,"where to_char(a.stat_date,'yyyy-MM') <= '"+ FORMAT(sStart_mon,'yyyy-MM') +"'","")} ORDER BY to_char(t.stat_date,'MM') \ No newline at end of file