ORACLE 数据库 竖表转横表

https://www.cnblogs.com/ipusr/articles/587271.html

 

 SELECT DECODE_ORACLE(t.grade_id,1,'一年级',2,'二年级',3,'三年级') AS '年级',

    max(DECODE_ORACLE(t.subject_name,'语文',t.max_score,0)) AS '语文', 

    max(DECODE_ORACLE(t.subject_name,'数学',t.max_score,0)) AS '数学', 

    max(DECODE_ORACLE(t.subject_name,'英语',t.max_score,0)) AS '英语',

    max(DECODE_ORACLE(t.subject_name,'政治',t.max_score,0)) AS '政治' 

    FROM test_table t

GROUP BY t.grade_id

 select DECODE_ORACLE(t.grade_id,1,'一年级',2,'二年级',3,'三年级') AS '年级',    max(DECODE_ORACLE(t.subject_name,'语文',t.max_score,0)) AS '语文',     max(DECODE_ORACLE(t.subject_name,'数学',t.max_score,0)) AS '数学',     max(DECODE_ORACLE(t.subject_name,'英语',t.max_score,0)) AS '英语',    max(DECODE_ORACLE(t.subject_name,'政治',t.max_score,0)) AS '政治'     from test_table t group by t.grade_id

posted @ 2022-03-15 11:08  小狗吃月亮  阅读(504)  评论(0编辑  收藏  举报