i have table 3 fields. want extract col_value corresponding type , amount , put in seperate column type , amount. how do that? given below table.
id | col_name | col_value 1 | type | abcd 1 | amount | 1234 2 | type | adcd 2 | amount | 224 and result want sql query
type | amount abcd | 1234
you can using conditional aggregation:
select max(case when col_name = 'type' col_value end) type, max(case when col_name = 'amount' col_value end) amount sampledata group id you add where clause specify id want return.
as ughai commented below, it'll better keep group by clause account multiple ids.
Comments
Post a Comment