时间:2021-07-01 10:21:17 帮助过:35人阅读
2.插入测试数据
insert into test_table (T1, T2, T3) values (‘张三‘, ‘语文‘, ‘88‘); insert into test_table (T1, T2, T3) values (‘张三‘, ‘数学‘, ‘99‘); insert into test_table (T1, T2, T3) values (‘张三‘, ‘英语‘, ‘100‘); insert into test_table (T1, T2, T3) values (‘李四‘, ‘语文‘, ‘79‘); insert into test_table (T1, T2, T3) values (‘李四‘, ‘数学‘, ‘100‘); insert into test_table (T1, T2, T3) values (‘李四‘, ‘英语‘, ‘99‘); insert into test_table (T1, T2, T3) values (‘王五‘, ‘语文‘, ‘99‘); insert into test_table (T1, T2, T3) values (‘王五‘, ‘数学‘, ‘100‘); insert into test_table (T1, T2, T3) values (‘王五‘, ‘英语‘, ‘98‘); insert into test_table (T1, T2, T3) values (‘李六‘, ‘语文‘, ‘88‘); insert into test_table (T1, T2, T3) values (‘李六‘, ‘英语‘, ‘99‘); insert into test_table (T1, T2, T3) values (‘李六‘, ‘数学‘, ‘100‘);
3.行转列之前效果
我们先查询一下现在的效果
4.下面是行转列写法
select * from test_table pivot (max(T3) for T2 in( ‘语文‘ as 语文, ‘数学‘ as 数学, ‘英语‘ as 英语 ))
效果如下:
这样就非常简单的实现了。
oracle行转列实现
标签:from sele weight for image 测试表 测试数据 pivot har