週に基づいてこの合計を計算しようとしていますが、次のコードを使用すると、明らかに週をグループに入れる必要があります。group by で week を使用しない方法はありますか?
cde channel 201305 201306 201307
rr1 2 0 0.6 1
現在は次のようになっています。
cde channel 201305 201306 201307
rr1 2 0 null null
rr1 2 null 0.6 null
rr1 2 null null 1
これは私のコードです
select cde,
case when week = '201305' then CAST((SUM(fin_acc_sum))AS FLOAT)/nullif(SUM(total),0) end as [201305],
case when week = '201306' then CAST((SUM(fin_acc_sum))AS FLOAT)/nullif(SUM(total),0) end as [201306],
case when week = '201307' then CAST((SUM(fin_acc_sum))AS FLOAT)/nullif(SUM(total),0) end as [201307],
channel
into #base2
from #acc_ref
group by cde,channel,week
order by channel,cde,week