leading-project/finereport/xiazuan/1_finance/4_收入预算完成情况.sql
2024-11-27 11:07:58 +08:00

40 lines
1.6 KiB
SQL

-- dic_门店
SELECT DISTINCT
comm_id AS id,/*门店*/
comm_name AS
FROM dim_organ_mapping
WHERE 1=1
${IF(LEN(p_area)>0," AND organ_code IN ('"+JOINARRAY(p_area,"','")+"')", "")}
-- dic_片区
SELECT DISTINCT
organ_code AS id,
organ_name AS
FROM dim_organ_mapping
-- report_收入成本利润预算填报
select
${if(len(p_area) == 0,"organ_code code, organ_name name,","comm_id code, comm_name name,")}
yr_month, category, yslx, index_income_target, index_income_fact, income_completion_rate
from(
select organ_code, organ_name, comm_id, comm_name, yr_month, category, '收入' yslx, index_income_target, index_income_fact, income_completion_rate
from ods_caiwu_feecollection
union all
select organ_code, organ_name, comm_id, comm_name, yr_month, category, '成本' yslx, index_cost_target, index_cost_fact, cost_completion_rate
from ods_caiwu_feecollection
union all
select organ_code, organ_name, comm_id, comm_name, yr_month, category, '利润' yslx, index_profit_target, profit_completion_rate, income_completion_rate
from ods_caiwu_feecollection
union all
select organ_code, organ_name, comm_id, comm_name, yr_month, category, '市拓' yslx, index_market_target, index_market_fact, market_completion_rate
from ods_caiwu_feecollection
) a where yslx = ${"'" + p_yslx + "'"}
${if(len(p_startdate) == 0,"","and yr_month = '" + p_startdate + "'")}
${if(len(p_area) == 0,"","and organ_code = '" + p_area+ "'")}