We're Moving!

The Vertica Forum is moving to a new OpenText Analytics Database (Vertica) Community.

Join us there to post discussion topics, learn about

product releases, share tips, access the blog, and much more.

Create My New Community Account Now


from rows to columns — Vertica Forum

from rows to columns

Hello guys, 

 

I want to convert A to B

 

ID question answer

1  name      John

1  age         23

2  name      Elias

2  age         67

3  name      Lionel

3  age         50

 

 

 

ID Name  Age

1  John    23

2  Elias    67

3  Lionel  50

 

 

Thanks for the help

 

Comments

  • Use subqueryes but with different predicates and then join by their id.

     

    WITH
    a AS
    (
    SELECT DISTINCT
    id,
    answer
    FROM
    test
    WHERE
    question='name'
    )
    ,
    b AS
    (
    SELECT DISTINCT
    id,
    answer
    FROM
    test
    WHERE
    question='age'
    )
    SELECT
    a.id,
    a.answer,
    b.answer
    FROM
    a
    JOIN
    b
    ON
    a.id=b.id
    ORDER BY
    a.id

    - i hope it helps.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file