除了每个活动的平均“分数”和每个活动的计数之外,我有三个选择声明提供参加特定活动的成员数量 - 医疗保健、宗教和体育。
每个事件的计数会有所不同。
每个查询单独工作,但我想将它们组合成一个查询。
我怎么做?
(select sum(case when Healthcare ='1' then 1 else 0 end) as [Healthcare_never],
sum(case when Healthcare ='2' then 1 else 0 end) as [Healthcare_not often],
sum(case when Healthcare ='3' then 1 else 0 end) as [Healthcare_average],
sum(case when Healthcare ='4' then 1 else 0 end) as [Healthcare_often],
sum(case when Healthcare ='5' then 1 else 0 end) as [Healthcare_very often]
,avg(Cast(Healthcare as float)) as Average
,count(Healthcare) as N_Healthcare
from Member
where Healthcare > '0' )
(select
sum(case when Religious ='1' then 1 else 0 end) as [Religious_never],
sum(case when Religious ='2' then 1 else 0 end) as [Religious_not often],
sum(case when Religious ='3' then 1 else 0 end) as [Religious_average],
sum(case when Religious ='4' then 1 else 0 end) as [Religious_often],
sum(case when Religious ='5' then 1 else 0 end) as [Religious_very often],
Avg(cast(Religious as float)) as Average
,count(Religious) as N_Religious
from Member
where Religious > '0' )
(select
sum(case when Sport ='1' then 1 else 0 end) as [Sport_never],
sum(case when Sport ='2' then 1 else 0 end) as [Sport_not often],
sum(case when Sport ='3' then 1 else 0 end) as [Sport_average],
sum(case when Sport ='4' then 1 else 0 end) as [Sport_often],
sum(case when Sport ='5' then 1 else 0 end) as [Sport_very often],
Avg(cast(Sport as float)) as Average
,count(Sport) as N_Sport
from Member
where Sport > '0' )