oracle怎么行转列 oracle的行转列函数

oracle如何实现行转列用union all
假设列名分别为 col1 cola colb...
【oracle怎么行转列 oracle的行转列函数】select col1,cola
from tabname
where ...
union all
select col1,colb
from tabname
where ...
union all
select col1,colc
from tabname
where ...
union all
select col1,cold
from tabname
where ...
union all
select col1,cole
from tabname
where ...
union all
select col1,colf
from tabname
where ...
oracle行转列sql怎么写?行转列的准则就是通过主键进行分组,之后对行其它字段加上sum()、max()、count()函数 , 里边用decode()这类函数进行处理,总之分组不要用到他就成 。
oracle 行转列 ,这个要怎么转witht(cate_displayname,info_waritername,count) as (
select '2014年','lizifeng',1 from dual
union all
select '历史沿革','wenqingwen',20 from dual
union all
select '领导讲话','lizifeng',3 from dual
)
SELECT cate_displayname,
nvl(lizifeng,0) as lizifeng,
nvl(wenqingwen,0) as wenqingwen
FROMt
PIVOT (
sum(count)---- pivot_clause
FOR info_waritername---- pivot_for_clause
IN('lizifeng' as lizifeng,'wenqingwen' as wenqingwen)---- pivot_in_clause
);
输出oracle怎么行转列:
CATE_DISPLAYNAMELIZIFENG WENQINGWEN
------------------------ ---------- ----------
2014年10
历史沿革020
领导讲话30
oracle 行转列测试表测了下,可以用,你看看,主要是先根据逗号进行分割,然后connect,level等于逗号的数目:
select id,nvl(substr(glbh,instr(glbh,',',1,lvl) 1,instr(glbh,',',1,lvl 1)-instr(glbh,',',1,lvl)-1),'kong') glbh
from(
select id,lvl,','||glbh||',' glbh
from test a,
(select level lvl from dual connect by level=
(select max(length(glbh)-length(replace(glbh,','))) 1 from test)) b
) t1
where substr(glbh,instr(glbh,',',1,lvl) 1,instr(glbh,',',1,lvl 1)-instr(glbh,',',1,lvl)-1) is not null
order by id,glbh;
oracle怎么行转列的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于oracle的行转列函数、oracle怎么行转列的信息别忘了在本站进行查找喔 。

    推荐阅读