I have a below MySQL table.
id Creation_Date Goals Alternative Value
-----------------------------------------------------------
1 2014-04-17 10:09:30 G1 A 0.86
2 2014-04-17 10:09:30 G1 B 0.87
3 2014-04-17 10:09:30 G2 A 0.5
4 2014-04-17 10:09:30 G2 B 0
I need a MySQL query for changing rows in columns and also need to their respective values like below.
**Output Require **
Alternative G1 G2
-------------------------------
A 0.86 0.50
B 0.87 0
Tried Solution :
I tried below query
select Alternative , max(case when Goals = 'G1' then round(value,2) end) as Goal1, max(case when Goals = 'G2' then round(value,2) end) as Goal2 from sgwebdb.dim_module group by id ;
but this is not giving required output ,this is giving below output
Alternative G1 G2
-------------------------------
A 0.86 Null
B 0.87 Null
A Null 0.50
B Null 0.00