SQL Combine 2 rows into 2 columns
I have a table that contains entries like this:
I would like to transfor it to something like this:
Can't find how to do so with a group by only. Am I missing anything?
Thanks in advance for your help
SELECT Entity, MAX(CASE WHEN Type=Auto THEN Value ELSE NULL END) AS ValueAuto, MAX(CASE WHEN Type=Manual THEN Value ELSE NULL END) AS ValueMaual FROM tableName GROUP BY Entity
above query returns the good values if we have only two types, If I don't know how many groups are there in the table, dynamically how can do with the case statement.
Use UN-PIVOT is the best options to solve the above requirements.