0

I have a table that contains entries like this:

enter image description here

I would like to transfor it to something like this:

enter image description here

Can't find how to do so with a group by only. Am I missing anything?

Thanks in advance for your help

2 Answers 2

3
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
Sign up to request clarification or add additional context in comments.

2 Comments

For completeness we will need to include region the group by and in the select list.
Thank you. How would you do if the 'Value' was actually string?
0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.