-- dict_1_片区

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



-- report_出租分析组合图

SELECT
    `type`,
    SUM(IFNULL(construction_area,0))/10000 AS 资产面积,
    SUM(IFNULL(lease_area,0))/10000 AS 出租面积,
    SUM(IFNULL(lease_area,0))/SUM(IFNULL(construction_area,0)) AS 出租率
FROM dws_business_rent_rate_d
         ${IF(LEN(p_project) > 0," AND project_id IN ('"+JOINARRAY(p_project,"','")+"')", "")}
GROUP BY `type`
;


-- 出租率

SELECT
    `type`
     , sum(lease_area)/sum(construction_area) rent_rate
FROM dws_business_rent_rate_d
WHERE 1=1
    ${IF(LEN(p_project) > 0," AND project_id IN ('"+JOINARRAY(p_project,"','")+"')", "")}
group by `type`
;


-- 出租面积

SELECT
    project_id
     , project_name
     , `type`
     , construction_area/10000 construction_area
     , lease_area/10000 lease_area
     , lease_area/construction_area rent_rate
FROM dws_business_rent_rate_d
         ${IF(LEN(p_project) > 0," AND project_id IN ('"+JOINARRAY(p_project,"','")+"')", "")}
;


-- 收款金额

SELECT
    project_id
     , project_name
     , accrual_month
     , current_sure_money/10000 current_sure_money
     , received_money/10000 received_money
     , areare_money/10000 areare_money
FROM dws_business_bill_m
where left(accrual_month,7) = '${p_ym}'
    ${IF(LEN(p_project) > 0," AND project_id IN ('"+JOINARRAY(p_project,"','")+"')", "")}