Need to convert columns into a row

Database
Enthusiast

Need to convert columns into a row

application_id epx eqi tu
1234 0.0 ? ?
1234 ? 5.0 ?
1234 ? ? 4.0

I need to convert above data into a single row like:

application_id epx's value eqi's value tu's value

please tell how to implement it??
2 REPLIES
Enthusiast

Re: Need to convert columns into a row

Manish Shekhar

if each row only has one value populated at any given time (other values are NULL)
then you can just group by the application_id and sum the other fields

application_id epx eqi tu
1234 0.0 ? ?
1234 ? 5.0 ?
1234 ? ? 4.0

select application_id, sum(epx) as epx_val, sum(eqi) as equ_val, sum(tu) as tu_val
from tableA
group by 1;

Hope that is what you want.
N/A

Re: Need to convert columns into a row

But what if all the 3 columns (apart from PI) have values and let us say if the o/p should have one row only with the values concatenated.

Table structure:

A xxx 1234 abc
A yyy 4567 df
A zzZ 3456 g

O/P should be:

A "xxx, yyyy, zzzz" "1234, 4567, 3456" "abc, df, g"

Thanks,
Srini