1

I'm looking to pivot multiple rows into columns. But when i use Max or Min in Pivot, its returning only one row. I want to display all the rows. Can any one help with this ?

From: enter image description here

To: enter image description here

1 Answer 1

2

You can use conditional aggregation:

select object_key,
       max(case when name = 'OBJECT_NAME' then value end) as object_name,
       max(case when name = 'Start Time' then value end) as start_time,
       max(case when name = 'End Time' then value end) as end_time,
       max(case when name = 'row_count' then value end) as row_count,
       max(case when name = 'Execution Time' then value end) as execution_time
from t
group by object_key;

I'm not sure why you specify "no aggregation" in the question.

If you really have an aversion to aggregation use can use joins:

select ton.object_key, ton.value as object_name,
       ts.value as start_time, te3.value as end_time,
       . . 
from t ton on
     t ts
     on ton.object_key = ts.object_key join
     t te
     on ton.object_key = t3.ojbect_key. join
     . . . ;
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot Gordon ! I was just thinking hard on pivot but failed to see case when option available :) This worked as i expected. Thanks once again

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.