leading-project/dw/dws/dws_operation_room_park_info_d.sql

32 lines
1.4 KiB
MySQL
Raw Permalink Normal View History

2024-07-21 22:06:45 +08:00
select
c.organ_code, c.organ_name, c.comm_id, c.comm_name
, a.room_num
, a.accept_num
, a.decorate_num
, a.check_ins_num
, a.vacant_num room_vacant_num
, b.park_num
, b.vacant_num park_vacant_num
from (
select CommID
, count(*) room_num
, sum(case when StateName in ('已接房未装修','已装修未入住','已入住(业主自住)','已入住(二手房)','已入住(租户)') then 1 else 0 end) accept_num
, sum(case when StateName in ('已装修未入住','已入住(业主自住)','已入住(二手房)','已入住(租户)') then 1 else 0 end) decorate_num
, sum(case when StateName in ('已入住(业主自住)','已入住(二手房)','已入住(租户)') then 1 else 0 end) check_ins_num
, sum(case when StateName in ('未售') then 1 else 0 end) vacant_num
from dim_room_d a
left join dim_room_state_d b
on a.RoomState = b.RoomState
group by CommID
) a
left join (
select
CommID
, count(*) park_num
, sum(case when UseState = '闲置' then 1 else 0 end) vacant_num
from dim_parking_info_d
group by CommID
) b
on a.CommID = b.CommID
inner join (select distinct organ_code, organ_name, comm_id, comm_name from dim_organ_mapping) c
on a.CommID = c.comm_id