0

Is there a quick way to transfom a Table like this:

FIELD   |  VALUE
+-------+----------+
Address |  here
Name    |  Rainer
Tel     |  01234567
Other   |  idk

Into this:

Address | Name     | Tel     | Other
+-------+----------+---------+----------+
here    |  Rainer  | 01234567| idk
0

2 Answers 2

2

You can also use pivot method :

select * 
  from tab
 pivot(
       max(value) for field in ( 'Address' as "Address", 
                                 'Name'    as "Name", 
                                 'Tel'     as "Tel", 
                                 'Other'   as "Other" ) ) 

Demo

Sign up to request clarification or add additional context in comments.

2 Comments

You don't need the nested sub-query. You can just do SELECT * FROM tab PIVOT ...
you'rewelcome@DropMania
1

Use conditional aggregation:

select
    max(case when field = 'Address' then value end) Address,
    max(case when field = 'Name' then value end) Name
    max(case when field = 'Tel' then value end) Tel
    max(case when field = 'Other' then value end) Other
from mytable

In normal situation, you would need a column to group by, like for example a user id, so you can generate several records from the initial content.

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.