ITPub博客

首页 > IT职业 > IT生活 > 行转列

行转列

原创 IT生活 作者:atgc 时间:2007-01-14 12:29:44 0 删除 编辑
SQL> select * from test;

ID MC
---------- -------------
1 11111
1 22222
2 11111
2 22222
3 11111
3 22222
3 33333

已选择7行。

SQL> select id,ltrim(max(sys_connect_by_path(mc,',')),',') row2col
from (select id,mc,
id+(row_number() over(order by id)) node_id,
row_number() over(partition by id order by id) rn
from test)
start with rn = 1
connect by node_id-1 = prior node_id
group by id
order by id;

ID ROW2COL
---------- -------------------------------------------------------------
1 11111,22222
2 11111,22222
3 11111,22222,33333

SQL> select id,replace(max(sys_connect_by_path(mc,',')),',') row2col
from (select id,mc,
id+(row_number() over(order by id)) node_id,
row_number() over(partition by id order by id) rn
from test)
start with rn = 1
connect by node_id-1 = prior node_id
group by id
order by id;

ID ROW2COL
---------- ------------------------------------------------------------
1 1111122222
2 1111122222
3 111112222233333
[@more@]

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/94041/viewspace-890239/,如需转载,请注明出处,否则将追究法律责任。

上一篇: 没有了~
下一篇: sfdsfdsfd
请登录后发表评论 登录
全部评论

注册时间:2008-01-18

  • 博文量
    22
  • 访问量
    216939