各イベントの平均「スコア」とカウントに加えて、特定のイベント (ヘルスケア、宗教、スポーツ) に参加するメンバーの数を提供する 3 つの select ステートメントがあります。
回数はイベントごとに異なります。
各クエリは個別に機能しますが、それらを 1 つのクエリに結合したいと考えています。
それ、どうやったら出来るの?
(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' )