oracle行转列pivot动态 Oracle列转行,行转列?
Oracle列转行,行转列?
oracle下可以用函数decode处理:
select 产品名称,
sum(decode(季度,"第一季度",销售额,0)) 第一季度销售额,
sum(decode(季度,"第二季度",销售额,0)) 第二季度销售额,
sum(decode(季度,"第三季度",销售额,0)) 第三季度销售额,
sum(decode(季度,"第四季度",销售额,0)) 第四季度销售额,
from 表名
group by 产品名称
oracle这种数据pivot或者其他怎么将key做字段str作为值来行转列(str值是字符串?
SELECT*FROM(SELECTkey,strFROMtablet)pivot(max(str)forkeyin("hyl","ls","ryhl","yqwd"))
Oracle实现行转换成列的方法?
数据表示例:假设要将name值作为行,course值作为列,转换后效果为:对应的SQL如下:方法1:使用表连接SELECT DISTINCT a.name,(SELECT score FROM grade b WHEREa.name=b.name AND b.course="语文") AS "语文",(SELECT score FROM grade b WHEREa.name=b.name AND b.course="数学") AS "数学",(SELECT score FROM grade b WHEREa.name=b.name AND b.course="英语") AS "英语"FROM grade a方法2:使用分组SELECT name,SUM(CASE course WHEN "语文" THEN score END) AS "语文",SUM(CASE course WHEN "数学" THEN score END) AS "数学",SUM(CASE course WHEN "英语" THEN score END) AS "英语"FROM grade GROUP BY name
sql怎样将行的值变为列?
你这是Oracle数据库,给你看看我写的:
列转行
录入经营范围时候会遇到列传行的问题解决方案如下:
在temp1 表有一下字段内容:
一条sql转化列传行效果
select a,zj,zjname from temp1 unpivot(zjname for zj in(b,c,d,e,f,g,h,i,j))
行转列:
select * from tbname
行转列之后的数据:
select pud, listagg(ud, ",") within group(order by null) as ud
from tbname
group by pud
oracle行转列pivot动态 oracle pivot函数 oracle行转列经典实现
版权声明:本文内容由互联网用户自发贡献,本站不承担相关法律责任.如有侵权/违法内容,本站将立刻删除。