zoukankan      html  css  js  c++  java
  • oracle分组后合并其中一个字段

    来自https://blog.csdn.net/gaoyao99409/article/details/19003729

    select m.parent_id,
                   m.start_date,
                   wmsys.wm_concat(m.cleck_name) As name,
                   wmsys.wm_concat(m.userId) As userId,
                   max(rowid) as rid
              from (select t.parent_id,
                           to_char(t.start_date, 'yyyy-MM-dd') start_date,
                           s.cleck_name,
                           s.user_orderby,
                           t.sche_type,
                           s.id as userId
                      from oa_assistant_schedulerplan t, s_user s
                     where t.user_id = s.id(+)
                       and t.sche_type != '1'
                       and t.parent_id is not null
                     order by s.user_orderby) m

             group by m.parent_id, m.start_date

    按parent_id和start_date分组后合并每个组的cleck_name和userId

    另一个实例:

    来自http://blog.sina.com.cn/s/blog_56d8ea900100zlwv.html

    数据库的结构如下:

    no   item

    01    AA
    01    BB
    02    CC
    02    DD
    02    EE
    03    FF
    04    GG
    04    HH

    希望将no相同的列整合为一条记录如下
    no   items
    01   AA,BB
    02   CC,DD,EE
    03    FF
    04   GG,HH


    MYSQL中,直接有group_contact函数了,如下:
      select id,group_contact(items) from TABLE group by id

    而oracle中,对应的有wm_contact,摘抄例子如下:
    select id,wmsys.wm_concat(items) name from table
    group by id;
  • 相关阅读:
    C# 多线程详解 Part.02(UI 线程和子线程的互动、ProgressBar 的异步调用)
    ubuntu 18.04安装ftp服务器
    ubuntu 18.04设置开机自动挂载移动硬盘
    使用apache commons net进行ftp传输
    Navicat连接MySQL 8出现2059
    Eclipse配置tomcat
    MySQL从.ibd文件中恢复数据
    MySQL建表时添加备注以及查看某一张表的备注信息
    在node.js中使用Set
    Java测试当前应用所占用的内存示例
  • 原文地址:https://www.cnblogs.com/hm1990hpu/p/9254573.html
Copyright © 2011-2022 走看看