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
DropMania
  • 123
  • 1
  • 11

2 Answers2

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

Barbaros Özhan
  • 59,113
  • 10
  • 31
  • 55
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.

GMB
  • 216,147
  • 25
  • 84
  • 135