Oracle查询结果行转列,列转行

行转列

select * from (select name, nums from demo/*任意查询语句*/) pivot (sum(nums) for name in ('测试1' 测试1, '测试2', '测试3'));

也可以用wm_concat函数

列转行

select id , name,xx,demo from Fruit unpivot (demo for xx in (q1, q2, q3) )

demo是数据列转行以后的字段名
xx 是原来那些字段显示的字段名(不是原表字段名,可以随便写)
in里面是要转行的列名
posted @ 2018-06-11 14:03  Ice_Blue_Brother  阅读(2474)  评论(0编辑  收藏  举报