zoukankan      html  css  js  c++  java
  • 行转列

    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
  • 相关阅读:
    前端 -- html
    MySQL索引
    Python操作MySQL
    MySQL表操作进阶
    MySQL表操作基础
    Github使用教程
    Android开发面试题
    MYSQL学习记录
    Java开发从零到现在
    JavaWeb(JSP/Servlet/上传/下载/分页/MVC/三层架构/Ajax)
  • 原文地址:https://www.cnblogs.com/danghuijian/p/4400856.html
Copyright © 2011-2022 走看看