资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

如何行转列oracle,怎样将列转成行

Oracle列转行,行转列

oracle下可以用函数decode处理:

创新互联:公司2013年成立为各行业开拓出企业自己的“网站建设”服务,为1000多家公司企业提供了专业的成都网站设计、成都网站建设、网页设计和网站推广服务, 按需网站建设由设计师亲自精心设计,设计的效果完全按照客户的要求,并适当的提出合理的建议,拥有的视觉效果,策划师分析客户的同行竞争对手,根据客户的实际情况给出合理的网站构架,制作客户同行业具有领先地位的。

select 产品名称,

sum(decode(季度,'第一季度',销售额,0)) 第一季度销售额,

sum(decode(季度,'第二季度',销售额,0)) 第二季度销售额,

sum(decode(季度,'第三季度',销售额,0)) 第三季度销售额,

sum(decode(季度,'第四季度',销售额,0)) 第四季度销售额,

from 表名

group by 产品名称;

ORAClE sql如何实现行转列?

如果“站名”、“条码”、“时间”都是一样的话,可以这么写:

with

t_temp as (select row_number() over (partition by station_name order by param_name asc) id, t.* from t),

t_temp1 as (select * from t_temp where id = 1),

t_temp2 as (select * from t_temp where id = 2),

t_temp3 as (select * from t_temp where id = 3)

select '站名' col1, '条码' col2, t_temp1.参数名 col3, t_temp2.参数名 col4, t_temp3.参数名 col5, '时间' col6

from t_temp1, t_temp2, t_temp3

where t_temp1.站名 = t_temp2.站名

and t_temp2.站名 = t_temp3.站名

union all

select t_temp1.站名, t_temp1.条码, to_char(t_temp1.数值), to_char(t_temp2.数值), to_char(t_temp3.数值), to_char(t_temp1.时间)

from t_temp1, t_temp2, t_temp3

where t_temp1.站名 = t_temp2.站名

and t_temp2.站名 = t_temp3.站名

oracle数据库里面如何把一行数据转化为列显示

可用union all来实现。

如test表中数据如下:

现要将id为3的一条按列显示,可用如下语句:

select to_char(id) str from test where id=3

union all

select name from test where id=3;

查询结果:

oracle行转列sql怎么写?

行转列的准则就是通过主键进行分组,之后对行其它字段加上sum()、max()、count()函数,里边用decode()这类函数进行处理,总之分组不要用到他就成。


文章标题:如何行转列oracle,怎样将列转成行
网站路径:http://cdkjz.cn/article/dsisceh.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220