08-25-2018 04:34 PM
I want to convert columns as rows as per user requirement. I know that this can be done using UNION ALL but I have 60 columns need to be converted. If I go with UNION ALL then I would need to write 60 UNION ALLs which will impact the performance.
Is there any direct way of converting columns to rows like using any functions etc.,
08-26-2018 09:33 PM
Hi, you dont have to union 60 times, you can do this:
when 'sales' then t.sales
when 'quantity' then t.quantity
end value from mytable t
cross join (
select 'sales' metric union all
select 'quantity' metric
08-27-2018 04:47 AM
Yes, it looks good.
Since we go with cross join doesn't it effect the performance?
If I have 100000 records then if I go with 10 UNION ALL then the count of records will go to 1million.
Is there any suggestion please to improve the performance with this approach?
08-29-2018 03:57 AM