销售业绩组合表样式优化

This commit is contained in:
yangkunan 2024-11-12 18:15:06 +08:00
parent 219845a129
commit e7f0060125

View File

@ -7,11 +7,7 @@ SELECT
${if(FIND('发货件数', sIndex)>0," ROUND(SUM(T1.ship_num) / 10000,2) AS 发货件数,","")} ${if(FIND('发货件数', sIndex)>0," ROUND(SUM(T1.ship_num) / 10000,2) AS 发货件数,","")}
${if(FIND('发货瓶数', sIndex)>0," ROUND(SUM(T1.ship_botnum),0) AS 发货瓶数,","")} ${if(FIND('发货瓶数', sIndex)>0," ROUND(SUM(T1.ship_botnum),0) AS 发货瓶数,","")}
${if(FIND('实物库存', sIndex)>0," ROUND(SUM(T1.real_amt) / 10000,2) AS 实物库存,","")} ${if(FIND('实物库存', sIndex)>0," ROUND(SUM(T1.real_amt) / 10000,2) AS 实物库存,","")}
-- ${if(len(sIndex)=0," max(1)","")}
-- ${if(len(sIndex)>0," 1","")}
${if(len(sIndex)>0&& FIND(sIndex,sIndex)>0," 1","")} ${if(len(sIndex)>0&& FIND(sIndex,sIndex)>0," 1","")}
FROM FROM
( (
-- 销售订单(订单金额) -- 销售订单(订单金额)
@ -35,36 +31,28 @@ FROM
,0 AS ship_botnum -- 发货瓶数 ,0 AS ship_botnum -- 发货瓶数
,0 AS real_amt -- 实物库存 ,0 AS real_amt -- 实物库存
FROM dm.v_ag_sal_order -- 销售订单视图 FROM dm.v_ag_sal_order -- 销售订单视图
WHERE 1 = 1 WHERE order_time >= '${CONCATENATE(sStart_date," 00:00:00.000")}'
-- AND TO_CHAR(order_time, 'YYYY-MM-DD') >= '2024-10-11' AND order_time < '${CONCATENATE(sEnd_date," 00:00:00.000")}'
-- AND TO_CHAR(order_time, 'YYYY-MM-DD') < '${sEndDate}' -- 事业部
${if(len(sBu) == 0,"","and bu_code IN ('"+sBu+"')")}
${SWITCH(sDateGroup -- 大区
,"'y'","AND LEFT(order_time, 4) > LFET('" + sStartDate + "', 4) AND LFET(order_time, 4) < LFET('" + sEndDate + "', 4)" ${if(len(sRegion) == 0,"","and region_code IN ('"+sRegion+"')")}
,"'q'","AND TO_CHAR(order_time, 'YYYY-MM-DD') > TO_CHAR('" + sStartDate + "', 'YYYY-MM-DD') AND TO_CHAR(order_time, 'YYYY-MM-DD') < TO_CHAR('" + sEndDate + "', 'YYYY-MM-DD')" -- 办事处
,"'m'","AND LFET(order_time,7) > LFET('" + sStartDate + "', 7) AND LFET(order_time, 7) < LFET('" + sEndDate + "', 7)" ${if(len(sOffice) == 0,"","and office_code IN ('"+ sOffice+"')")}
,"'d'","AND TO_CHAR(order_time, 'YYYY-MM-DD') > TO_CHAR('" + sStartDate + "', 'YYYY-MM-DD') AND TO_CHAR(order_time, 'YYYY-MM-DD') < TO_CHAR('" + sEndDate + "', 'YYYY-MM-DD')")} -- 城市单元
${if(len(sCu) == 0,"","and city_unit_code IN ('"+sCu+"')")}
-- 省
-- 事业部 ${if(len(sProvince) == 0,"","and province_name IN ('"+ sProvince+"')")}
${if(len(sBu) == 0,"","and bu_code IN ('"+sBu+"')")} -- 市
-- 大区 ${if(len(sCity) == 0,"","and city_name IN ('"+ sCity+"')")}
${if(len(sCompRegion) == 0,"","and region_code IN ('"+ sCompRegion+"')")} -- 经销商
-- 办事处 ${if(len(sDeal) == 0,"","and deal_code IN ('"+sDeal+"')")}
${if(len(sOffice) == 0,"","and office_code IN ('"+ sOffice+"')")} -- 产品线
-- 城市单元 ${if(len(sPl) == 0,"","and pl_name IN ('"+ sPl+"')")}
${if(len(sCityUnit) == 0,"","and city_unit_code IN ('"+ sCityUnit+"')")} -- 品项
-- 省 ${if(len(sPi_name) == 0,"","and pi_name IN ('"+ sPi_name+"')")}
${if(len(sProvince) == 0,"","and province_name IN ('"+ sProvince+"')")} -- 产品
-- 市 ${if(len(sProd) == 0,"","and product_code IN ('"+sProd+"')")}
${if(len(sCity) == 0,"","and city_name IN ('"+ sCity+"')")}
-- 产品线
${if(len(sPl) == 0,"","and pl_name IN ('"+ sPl+"')")}
-- 品项
${if(len(sPi) == 0,"","and pi_name IN ('"+ sPi+"')")}
-- 子主经销商
${if(sDeal == 1,if(len(sDealName) == 0,"","and deal_code IN ('"+ sDealName+"')"),if(len(sDealName) == 0,"","and src_deal_code IN ('"+ sDealName +"')"))}
GROUP BY GROUP BY
bu_name -- 事业部名称 bu_name -- 事业部名称
,region_name -- 大区名称 ,region_name -- 大区名称
@ -100,27 +88,28 @@ FROM
,0 AS ship_botnum-- 发货瓶数 ,0 AS ship_botnum-- 发货瓶数
,0 AS real_amt -- 实物库存 ,0 AS real_amt -- 实物库存
FROM dm.v_ag_sal_contract -- 合同表 产品+合同ID FROM dm.v_ag_sal_contract -- 合同表 产品+合同ID
WHERE 1 = 1 WHERE signed_date >= '${CONCATENATE(sStart_date," 00:00:00.000")}'
AND TO_CHAR(signed_date, 'YYYY-MM-DD') >= '${sStartDate}' AND signed_date < '${CONCATENATE(sEnd_date," 00:00:00.000")}'
AND TO_CHAR(signed_date, 'YYYY-MM-DD') < '${sEndDate}' -- 事业部
-- 事业部
${if(len(sBu) == 0,"","and bu_code IN ('"+sBu+"')")} ${if(len(sBu) == 0,"","and bu_code IN ('"+sBu+"')")}
-- 大区 -- 大区
${if(len(sCompRegion) == 0,"","and region_code IN ('"+ sCompRegion+"')")} ${if(len(sRegion) == 0,"","and region_code IN ('"+sRegion+"')")}
-- 办事处 -- 办事处
${if(len(sOffice) == 0,"","and office_code IN ('"+ sOffice+"')")} ${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(sProvince) == 0,"","and province_name IN ('"+ sProvince+"')")} ${if(len(sProvince) == 0,"","and province_name IN ('"+ sProvince+"')")}
-- 市 -- 市
${if(len(sCity) == 0,"","and city_name IN ('"+ sCity+"')")} ${if(len(sCity) == 0,"","and city_name IN ('"+ sCity+"')")}
-- 产品线 -- 经销商
${if(len(sDeal) == 0,"","and deal_code IN ('"+sDeal+"')")}
-- 产品线
${if(len(sPl) == 0,"","and pl_name IN ('"+ sPl+"')")} ${if(len(sPl) == 0,"","and pl_name IN ('"+ sPl+"')")}
-- 品项 -- 品项
${if(len(sPi) == 0,"","and pi_name IN ('"+ sPi+"')")} ${if(len(sPi_name) == 0,"","and pi_name IN ('"+ sPi_name+"')")}
-- 子主经销商 -- 产品
${if(sDeal == 1,if(len(sDealName) == 0,"","and deal_code IN ('"+ sDealName+"')"),if(len(sDealName) == 0,"","and src_deal_code IN ('"+ sDealName +"')"))} ${if(len(sProd) == 0,"","and product_code IN ('"+sProd+"')")}
GROUP BY GROUP BY
bu_name -- 事业部名称 bu_name -- 事业部名称
@ -157,25 +146,28 @@ FROM
,0 AS real_amt -- 实物库存 ,0 AS real_amt -- 实物库存
FROM dm.v_ag_sal_collection -- 销售回款 FROM dm.v_ag_sal_collection -- 销售回款
WHERE 1=1 WHERE 1=1
AND TO_CHAR(bill_date, 'YYYY-MM-DD') >= '${sStartDate}' AND bill_date >= '${CONCATENATE(sStart_date," 00:00:00.000")}'
AND TO_CHAR(bill_date, 'YYYY-MM-DD') < '${sEndDate}' AND bill_date < '${CONCATENATE(sEnd_date," 00:00:00.000")}'
-- 事业部 -- 事业部
${if(len(sBu) == 0,"","and bu_code IN ('"+sBu+"')")} ${if(len(sBu) == 0,"","and bu_code IN ('"+sBu+"')")}
-- 大区 -- 大区
${if(len(sCompRegion) == 0,"","and region_code IN ('"+ sCompRegion+"')")} ${if(len(sRegion) == 0,"","and region_code IN ('"+sRegion+"')")}
-- 办事处 -- 办事处
${if(len(sOffice) == 0,"","and office_code IN ('"+ sOffice+"')")} ${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(sProvince) == 0,"","and province_name IN ('"+ sProvince+"')")} ${if(len(sProvince) == 0,"","and province_name IN ('"+ sProvince+"')")}
-- 市 -- 市
${if(len(sCity) == 0,"","and city_name IN ('"+ sCity+"')")} ${if(len(sCity) == 0,"","and city_name IN ('"+ sCity+"')")}
-- 经销商
${if(len(sDeal) == 0,"","and deal_code IN ('"+sDeal+"')")}
-- 产品线 -- 产品线
${if(len(sPl) == 0,"","and pl_name IN ('"+ sPl+"')")} ${if(len(sPl) == 0,"","and pl_name IN ('"+ sPl+"')")}
-- 子主经销商 -- 品项
${if(sDeal == 1,if(len(sDealName) == 0,"","and deal_code IN ('"+ sDealName+"')"),if(len(sDealName) == 0,"","and src_deal_code IN ('"+ sDealName +"')"))} ${if(len(sPi_name) == 0,"","and pi_name IN ('"+ sPi_name+"')")}
-- 产品
${if(len(sProd) == 0,"","and product_code IN ('"+sProd+"')")}
GROUP BY GROUP BY
bu_name -- 事业部名称 bu_name -- 事业部名称
,region_name -- 大区名称 ,region_name -- 大区名称
@ -210,27 +202,28 @@ FROM
,0 AS real_amt -- 实物库存 ,0 AS real_amt -- 实物库存
FROM dm.v_ag_sal_deliver FROM dm.v_ag_sal_deliver
WHERE 1=1 WHERE 1=1
AND TO_CHAR(deli_time, 'YYYY-MM-DD') >= '${sStartDate}' AND deli_time >= '${CONCATENATE(sStart_date," 00:00:00.000")}'
AND TO_CHAR(deli_time, 'YYYY-MM-DD') < '${sEndDate}' AND deli_time < '${CONCATENATE(sEnd_date," 00:00:00.000")}'
-- 事业部 -- 事业部
${if(len(sBu) == 0,"","and bu_code IN ('"+sBu+"')")} ${if(len(sBu) == 0,"","and bu_code IN ('"+sBu+"')")}
-- 大区 -- 大区
${if(len(sCompRegion) == 0,"","and region_code IN ('"+ sCompRegion+"')")} ${if(len(sRegion) == 0,"","and region_code IN ('"+sRegion+"')")}
-- 办事处 -- 办事处
${if(len(sOffice) == 0,"","and office_code IN ('"+ sOffice+"')")} ${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(sProvince) == 0,"","and province_name IN ('"+ sProvince+"')")} ${if(len(sProvince) == 0,"","and province_name IN ('"+ sProvince+"')")}
-- 市 -- 市
${if(len(sCity) == 0,"","and city_name IN ('"+ sCity+"')")} ${if(len(sCity) == 0,"","and city_name IN ('"+ sCity+"')")}
-- 经销商
${if(len(sDeal) == 0,"","and deal_code IN ('"+sDeal+"')")}
-- 产品线 -- 产品线
${if(len(sPl) == 0,"","and pl_name IN ('"+ sPl+"')")} ${if(len(sPl) == 0,"","and pl_name IN ('"+ sPl+"')")}
-- 品项 -- 品项
${if(len(sPi) == 0,"","and pi_name IN ('"+ sPi+"')")} ${if(len(sPi_name) == 0,"","and pi_name IN ('"+ sPi_name+"')")}
-- 子主经销商 -- 产品
${if(sDeal == 1,if(len(sDealName) == 0,"","and deal_code IN ('"+ sDealName+"')"),if(len(sDealName) == 0,"","and src_deal_code IN ('"+ sDealName +"')"))} ${if(len(sProd) == 0,"","and product_code IN ('"+sProd+"')")}
GROUP BY GROUP BY
bu_name -- 事业部名称 bu_name -- 事业部名称
,region_name -- 大区名称 ,region_name -- 大区名称
@ -265,28 +258,29 @@ FROM
,0 AS ship_botnum-- 发货瓶数 ,0 AS ship_botnum-- 发货瓶数
,SUM(end_num * price) AS real_amt -- 实物库存金额 ,SUM(end_num * price) AS real_amt -- 实物库存金额
FROM dm.v_ag_sal_deal_stock FROM dm.v_ag_sal_deal_stock
WHERE 1=1 WHERE stock_year=left('${sEnd_date}',4)
AND CONCAT(stock_year, '-', stock_month, '-01') >= '${sStartDate}' AND stock_month < right('${sEnd_date}',2)
AND CONCAT(stock_year, '-', stock_month, '-01') < '${sEndDate}' AND stock_month >= right('${sStart_date}',2)
-- 事业部 -- 事业部
${if(len(sBu) == 0,"","and bu_code IN ('"+sBu+"')")} ${if(len(sBu) == 0,"","and bu_code IN ('"+sBu+"')")}
-- 大区 -- 大区
${if(len(sCompRegion) == 0,"","and region_code IN ('"+ sCompRegion+"')")} ${if(len(sRegion) == 0,"","and region_code IN ('"+sRegion+"')")}
-- 办事处 -- 办事处
${if(len(sOffice) == 0,"","and office_code IN ('"+ sOffice+"')")} ${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(sProvince) == 0,"","and province_name IN ('"+ sProvince+"')")} ${if(len(sProvince) == 0,"","and province_name IN ('"+ sProvince+"')")}
-- 市 -- 市
${if(len(sCity) == 0,"","and city_name IN ('"+ sCity+"')")} ${if(len(sCity) == 0,"","and city_name IN ('"+ sCity+"')")}
-- 经销商
${if(len(sDeal) == 0,"","and deal_code IN ('"+sDeal+"')")}
-- 产品线 -- 产品线
${if(len(sPl) == 0,"","and pl_name IN ('"+ sPl+"')")} ${if(len(sPl) == 0,"","and pl_name IN ('"+ sPl+"')")}
-- 品项 -- 品项
${if(len(sPi) == 0,"","and pi_name IN ('"+ sPi+"')")} ${if(len(sPi_name) == 0,"","and pi_name IN ('"+ sPi_name+"')")}
-- 子主经销商 -- 产品
${if(sDeal == 1,if(len(sDealName) == 0,"","and deal_code IN ('"+ sDealName+"')"),if(len(sDealName) == 0,"","and src_deal_code IN ('"+ sDealName +"')"))} ${if(len(sProd) == 0,"","and product_code IN ('"+sProd+"')")}
GROUP BY GROUP BY
bu_name -- 事业部名称 bu_name -- 事业部名称
,region_name -- 大区名称 ,region_name -- 大区名称
@ -300,5 +294,4 @@ FROM
,deal_name -- 经销商名称 ,deal_name -- 经销商名称
,src_deal_name -- 子经销商名称 ,src_deal_name -- 子经销商名称
)T1 )T1
${if(len(sDim)>0," GROUP BY " + sDim ," ")} ${if(len(sDim)>0," GROUP BY " + sDim ," ")}