Oracle,SQL自带行转列函数实现行转列操作
Mysql中实现行转列或者实现以下操作的实现:
使用max()函数与case......when........then.......else......end实现
eg: 表A select year ,
max(case month when '1' then amount else 0 end ) m1,
max(case month when '2' then amount else 0 end )m2,
max(case month when '3' then amount else 0 end ) m3
from A group by year
oracle中行转列的实现
SELECT a.* FROM A a pivot(MAX(a.amount) FOR month IN ('1','2','3'))a
既然有缘,何不关注一下!
春有百花秋有月,夏有凉风冬有雪!