SELECT
(
select string_agg(unit_name, '-->') as unit_chain from ( with recursive cte (id,unit_name) as (
select *, 1 as depath from t_unit where id = (select unit_id from t_role where id = t3.role_id) union all
select b.*,depath+1 from t_unit b inner join cte c on b.id=c.parent_id and b.deleted = 0 and c.deleted = 0)
select id,unit_name from cte WHERE cte.deleted = 0 ORDER BY depath desc) as t2
) as 组织机构,
t1.id as 房源id,
t6.real_name as 收房客户经理,
t2.building_name as 小区名称,
t1.building_no || '-' || t1.unit_no || '-' || room_no as 门牌号,
t3.rent_per_month as 收房月租金,
to_char(to_timestamp(t8.final_rent_day/1000),'yyyy-MM-dd') as 起租日,
to_char(to_timestamp(t4.start_date/1000),'yyyy-MM-dd') as 首次租赁开始时间,
t4.price as 首次出房租金,
CASE t4.pay_method
WHEN 1 THEN '月付'
WHEN 2 THEN '季付'
WHEN 3