Q: SQL: Combine multiple rows into a single row with more columns I have a dataset structured like this:
ID  |  Feedback type  |  Feedback value
1      Overall rating    5 
1      Duration          23.5
1      Representative    Steve
2      Overall rating    4 
2      Duration          47
2      Representative    Jane

Essentially, each set of three rows represents a single interaction.  What I want is a single row for each interaction, like this:
ID  |  Overall rating  |  Duration | Representative
1      5                  23.5       Steve
2      4                  47         Jane

I'm having a hard time figuring out the right way to make a subquery that will do this.  In Excel, I'd just get a list of my IDs and do vlookups into the raw table, but I'm not clear how to do that in SQL.  Thanks for any pointers!

A: This would be the ideal way to do it
SELECT *
FROM TableName
PIVOT(MAX([Feedback value])
      FOR [Feedback type] IN ([Overall rating], [Duration], [Representative])
     ) AS PVTTable

However, user is not able to use pivot, so this will work as well
SELECT [ID], 
       MAX(CASE WHEN [Feedback type] = 'Overall rating' 
                THEN [Feedback value] 
                ELSE '' END) AS 'Overall Rating',
       MAX(CASE WHEN [Feedback type] = 'Duration' 
                THEN [Feedback value] 
                ELSE '' END) AS 'Duration',
       MAX(CASE WHEN [Feedback type] = 'Representative' 
                THEN [Feedback value] 
                ELSE '' END) AS 'Representative'
FROM TableName
GROUP BY [ID]


A: I would have taken a different path:
SELECT T0.ID, T0.[Overall Rating], T1.Duration, T2.Representative

FROM (SELECT ID, [Feedback Value] AS 'Overall Rating' where [Feedback Type] = 'Overall Rating' FROM TableName) T0

LEFT JOIN (SELECT ID, [Feedback Value] AS 'Duration' where [Feedback Type] = 'Duration' FROM TableName) T1 ON T0.id = T1.id

LEFT JOIN (SELECT ID, [Feedback Value] AS 'Representative' where [Feedback Type] = 'Representative' FROM TableName) T2 ON T0.id = T2.id

Essentially, I'm creating "Sub tables" to query from -- one each for ratings, durations, and representatives. Because they're all linked to the same ID, you can create the table and then join them. Of course, this isn't going to be the most efficient method to create this query if it's a large table, but for something small like your example, it should work just fine. 
