Assumining你需要動態
例
Declare @SQL varchar(max) = '
Select *
From (
Select [ID_CLIENT]
,[Item] = concat(''PRICEFORID_TYPE'',[ID_TYPE])
,[Price]
From YourTable
) A
Pivot (max([Price]) For [Item] in (' + Stuff((Select Distinct ','+QuoteName(concat('PRICEFORID_TYPE',[ID_TYPE]))
From YourTable
Order By 1
For XML Path('')),1,1,'') + ')) p'
Exec(@SQL);
--Print @SQL
返回
生成的SQL看起來像這樣
Select *
From (
Select [ID_CLIENT]
,[Item] = concat('PRICEFORID_TYPE',[ID_TYPE])
,[Price]
From YourTable
) A
Pivot (max([Price]) For [Item] in ([PRICEFORID_TYPE1],[PRICEFORID_TYPE2])) p
什麼是您的輸入數據?您可以搜索「動態數據透視查詢」... – TriV