行转列
fd_name | fd_type | fd_total |
---|---|---|
a | type1 | 1 |
a | type2 | 2 |
a | type3 | 3 |
转成
fd_name | fd_type1_total | fd_type2_total | fd_type3_total |
---|---|---|---|
a | 1 | 2 | 3 |
sql
代码语言:javascript复制select fd_name
, max(case when fd_type = 'type1' then fd_total else 0 end) as fd_type1_total
, max(case when fd_type = 'type2' then fd_total else 0 end) as fd_type2_total
, max(case when fd_type = 'type3' then fd_total else 0 end) as fd_type3_total
from
t_mytable
group by fd_name