Redwan Agharoud
Redwan Agharoud

Reputation: 27

(HANA SQL) Show multiple values in one row

I am trying to complete the following:

Old situation

enter image description here

What I want

enter image description here

Upvotes: 0

Views: 835

Answers (1)

GMB
GMB

Reputation: 222482

For a fixed maximum number of target columns, you can use window functions and conditional aggregation:

select customer,
    max(case when rn = 1 then order_date end) as order_date_1,
    max(case when rn = 2 then order_date end) as order_date_2,
    max(case when rn = 3 then order_date end) as order_date_3
from (
    select t.*, row_number() over(partition by customer order by order_date) rn
    from mytable t
) t
group by customer

Upvotes: 1

Related Questions