使用 case when xxx='' else '' end 语句,将字段内的内容进行替代
使用union或者union all 来连接合并两个语句
select
(case when Household_Type='0' then '住户' when Household_Type='1' then '租户' else '未确定' end) as 'group',
count(*) as value,
CheckInDate as name
from Base_Households
group by Household_Type,CheckInDate
union
select
(case when [Status]='1' then '在住' when [Status]='9' then '迁出' else '未确定' end ) as 'group',
count(*) as value,
CheckInDate as name
from Base_Households
group by [Status],CheckInDate