行转列SQL

来源:互联网 发布:cassandra java 取数据 编辑:程序博客网 时间:2024/05/16 18:08

YEAR MO        SAL
---- -- ----------
1992 1       1234
1992 2       1234
1993 1       1234
1993 2       1234
1994 1       1234
1994 2       1234

6 rows selected.

SQL> select month,
 sum(case year when '1992' then sal end) "1992",
 sum(case year when '1993' then sal end) "1993",
 sum(case year when '1994' then sal end) "1994"
 from sal
 group by month; 

MO  1992     1993       1994
-- ---------- ---------- ----------
1  1234     1234       1234
2  1234     1234       1234

原创粉丝点击