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

Answers


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.


Need Your Help

creating alias in wamp

wamp wampserver

I have wamp site on port 81 ( i use IIS alot which is on port 80)

Ruby implementing access to members of collection by [closed]

ruby member

Is there any way to implement access to member of collection by []. I mean i have to program a linked list and i wanna access members by Coll[int]. Is there any way to do that?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.