0

これは私のソーステーブル(pivot_dummy)で旋回されるために列の間のすべての可能な組み合わせを得るために:SQLピボット - どのように

Source data Table

と私はPARAMETER_TYPEことによってそれを旋回させる必要がありますが、Parameter_valの間のすべての可能な組み合わせを必要とします。

SELECT nct_id, [Asset],[Indication], rowid 
FROM (SELECT nct_id,Parameter_val,parameter_type, rowid 
     FROM (Select *, 
        Row_Number() Over (Partition By nct_id,Parameter_type ORDER BY nct_id) RowId 
      from [dbo].[pivot_dummy] 
      ) a 
    ) s 
Pivot (
    max(parameter_val) 
     for Parameter_type in ([Asset], [Indication]) 
    ) as pivottable 

が、以下では、このコードの結果:この

Desired Output

のように私はそれを成し遂げるためにこのコードを使用しています何か

Current Output

は、誰かが助けてくださいことはできますか?

答えて

0

私が知る限り、pivotはまったく必要ありません。単純にa join

select pd1.nct_id, pd1.parameter_value as asset, pd2.parameter_value as indication 
from pivot_dummy pd1 join 
    pivot_dummy pd2 
    on pd1.nct_id = pd2.nct_id and 
     pd1.parameter_type = 'Asset' and 
     pd2.parameter_type = 'Indication'; 
+0

こんにちはゴードン!どうもありがとう! –

+0

こんにちはゴードン、これは2つの列(資産と表示)がある場合、私の問題を解決します。しかし実際には私は7つのコラムを枢動させ、その中でNCTIDに基づいて解決策を見つけることができます。私はまだピボットについて考えるべきですか? –

+0

@AnkurBansal。 。 。あなたが尋ねた質問に答えることは可能です。別の質問がある場合は、*新しい*質問としてそれを求めます。 –