に複数列を持つテーブルをアンピボット: my current table ピボットと、私はこのようになります。このテーブルを旋回させる必要があるTSQL
私は必要なものは、次のようになります13個の列を持つテーブルである: desired pivoted table
私はRazorSQL
でtsqlを使用しています。ここで私のコードは最終的なテーブルになりました。今度はそれをピボットする必要があります。 :
select s5.datess, ISNULL(s5.Active_And_Good,0) AS Active_And_Good, ISNULL(s5.Inactive_And_Good,0) AS Inactive_And_Good,
ISNULL(s5.Active_And_Bad,0) AS Active_And_Bad, ISNULL(s6.Inactive_And_Bad,0) AS Inactive_And_Bad
from
(select s3.dates as datess, s3.#Active_Good as Active_And_Good, s3.#Inactive_Good as Inactive_And_Good,
s4.Active_Bad as Active_And_Bad from
(select s1.Dates as dates, s1.Active_Good as #Active_Good, s2.Inactive_Good as #Inactive_Good from
(select count(DISTINCT Customer_Id) as Active_Good, Dates
from #fact_table
where Customer_Status = 1
group by Dates) as s1
full outer join
(select count(DISTINCT Customer_Id) as Inactive_Good, Dates
from #fact_table
where Customer_Status = 2
group by Dates) as s2
on s1.Dates=s2.Dates) as s3
full outer join
(select count(DISTINCT Customer_Id) as Active_Bad, Dates
from #fact_table
where Customer_Status = 3
group by Dates) as s4
on s3.dates= s4.Dates) as s5
full outer join
(select count(DISTINCT Customer_Id) as Inactive_And_Bad, Dates
from #fact_table
where Customer_Status = 4
group by Dates) as s6
on s5.datess= s6.Dates ;
ありがとうございました。それは働いた:) –
問題はありません。 〜:o) – GandRalph