列中有五类参数,分别为“未售”“已售”“大定”“小定”“保留”,要对每类参数包含的数据进行统计
关键sql语句:sum(case zhuangtai when '未售' then 1 else 0 end) as 未售
完整sql:
select project_name, 'zongshu'=count(*),sum(case zhuangtai when '未售' then 1 else 0 end) as 未售,sum(case zhuangtai when '已售' then 1 else 0 end) as 已售,sum(case zhuangtai when '大定' then 1 else 0 end) as 大定,sum(case zhuangtai when '小定' then 1 else 0 end) as 小定,sum(case zhuangtai when '保留' then 1 else 0 end) as 保留 from project_fj,project where project.id=project_fj.project_id GROUP BY project_name