统计每个楼栋表的房屋数量
SELECT
b.*,
sum(case when (h.id is not null) then 1 else 0 end) as houseNum
FROM
bs_building b
LEFT JOIN bs_house h ON b.id = h.building_id and h.deleted = 0
where b.deleted = 0
GROUP BY b.id
case sum 函数的其他例子
统计每个楼栋表的房屋数量
SELECT
b.*,
sum(case when (h.id is not null) then 1 else 0 end) as houseNum
FROM
bs_building b
LEFT JOIN bs_house h ON b.id = h.building_id and h.deleted = 0
where b.deleted = 0
GROUP BY b.id
case sum 函数的其他例子