如何行转列oracle,怎样将列转成行-成都创新互联网站建设

关于创新互联

多方位宣传企业产品与服务 突出企业形象

公司简介 公司的服务 荣誉资质 新闻动态 联系我们

如何行转列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://kswsj.cn/article/dsisceh.html

其他资讯