I have a table like below in SQL Server 2010
But I need an output like below
Please help me to solve, I need a select statement like how we are using pivot in Excel.
snvhrwxg1#
You can use Pivot table as :
SELECT [ID], [Data1] AS [Type1], [Data2] AS [Type2], [Data3] AS [Type3], [Data4] AS [Type4] FROM ( SELECT [ID], [Type], [Data] FROM table1 ) AS SourceTable PIVOT ( MAX([Data]) FOR [Type] IN ([Data1], [Data2], [Data3], [Data4]) ) AS PivotTable;
I hope this will help you!!
1条答案
按热度按时间snvhrwxg1#
You can use Pivot table as :
I hope this will help you!!