zoukankan      html  css  js  c++  java
  • 分组合并字符串


    ORACLE中表 test(a,b,c)有记录如下:
    A                 B                      C
    1                 XXX                   01
    2                 YYY                   01
    3                 KKK                   02
    4                 III                   02
    。。。。
    把C相同的B根据序号A串联起来,即得到这样的结果
     B           C
    XXXYYY       01
    KKKIII       02

    create table test(a int,b varchar2(100),c varchar2(100));
    insert into test
    select 1,'XXX','01' from dual union all 
    select 2,'YYY','01' from dual union all
    select 3,'KKK','02' from dual union all
    select 4,'III','02' from dual;

    select c,replace(substr(max(sys_connect_by_path(b, '|')), 2),'|','') b
    from (select b, c, row_number() over(partition by c order by 1) rn
    from test)
    start with rn = 1
    connect by rn - 1 = prior rn and c = prior c
    group by c;

  • 相关阅读:
    php......房屋租赁练习
    php......调研投票练习
    数据访问......单条件查询与多条件查询
    数据访问......简单练习
    数据访问......增删改查
    数据访问
    面向对象练习
    php正则表达式和数组
    php面向对象加载类
    php类和对象(二)
  • 原文地址:https://www.cnblogs.com/Bluer/p/977838.html
Copyright © 2011-2022 走看看