0

I need help in SQL. I have a table with this structure.

this structure:

What I need is a query to return the data like this.

this:

Thank you very much in advance!

Kind regards, bgergoe

S3S
  • 24,809
  • 5
  • 26
  • 45
bgergoe
  • 21
  • 4

1 Answers1

5

This has been asked and answered dozens of times but it is super simple to write out the code. Conditional aggregation is pretty straight forward and the code is far less obtuse than PIVOT. Here is how you would go about this.

SELECT ID
    , MAX(CASE WHEN Field = 'name' THEN Value END) AS name
    , MAX(CASE WHEN Field = 'phone number' THEN Value END) AS PhoneNumber
FROM YourTable
GROUP BY ID
Sean Lange
  • 33,028
  • 3
  • 25
  • 40