-- dic_片区


SELECT DISTINCT
    organ_code AS 片区id,
    organ_name AS 片区名称
FROM dim_organ_mapping


-- report_现金流

select
    ${if(len(p_area) == 0,"organ_name name","comm_name name")}
     , sum(sum_cash) sum_cash
from ods_caiwu_fullaperture
where 1=1
    ${if(len(p_startdate) == 0,"","and yr_month = '" + left(p_startdate,4) + right(p_startdate,2) + "'")}
      ${if(len(p_area) == 0,"","and organ_code = '" + p_area+ "'")}
group by ${if(len(p_area) == 0,"organ_name","comm_name")}
order by sum(sum_cash) desc