<legend id='ejCQ3'><style id='ejCQ3'><dir id='ejCQ3'><q id='ejCQ3'></q></dir></style></legend>
    1. <small id='ejCQ3'></small><noframes id='ejCQ3'>

    2. <tfoot id='ejCQ3'></tfoot>
      <i id='ejCQ3'><tr id='ejCQ3'><dt id='ejCQ3'><q id='ejCQ3'><span id='ejCQ3'><b id='ejCQ3'><form id='ejCQ3'><ins id='ejCQ3'></ins><ul id='ejCQ3'></ul><sub id='ejCQ3'></sub></form><legend id='ejCQ3'></legend><bdo id='ejCQ3'><pre id='ejCQ3'><center id='ejCQ3'></center></pre></bdo></b><th id='ejCQ3'></th></span></q></dt></tr></i><div id='ejCQ3'><tfoot id='ejCQ3'></tfoot><dl id='ejCQ3'><fieldset id='ejCQ3'></fieldset></dl></div>

          <bdo id='ejCQ3'></bdo><ul id='ejCQ3'></ul>

        在 Oracle 中连接和分组多行

        Concatenate and group multiple rows in Oracle(在 Oracle 中连接和分组多行)
          <bdo id='ZVaen'></bdo><ul id='ZVaen'></ul>
          • <small id='ZVaen'></small><noframes id='ZVaen'>

                <tbody id='ZVaen'></tbody>

              <legend id='ZVaen'><style id='ZVaen'><dir id='ZVaen'><q id='ZVaen'></q></dir></style></legend><tfoot id='ZVaen'></tfoot>

                <i id='ZVaen'><tr id='ZVaen'><dt id='ZVaen'><q id='ZVaen'><span id='ZVaen'><b id='ZVaen'><form id='ZVaen'><ins id='ZVaen'></ins><ul id='ZVaen'></ul><sub id='ZVaen'></sub></form><legend id='ZVaen'></legend><bdo id='ZVaen'><pre id='ZVaen'><center id='ZVaen'></center></pre></bdo></b><th id='ZVaen'></th></span></q></dt></tr></i><div id='ZVaen'><tfoot id='ZVaen'></tfoot><dl id='ZVaen'><fieldset id='ZVaen'></fieldset></dl></div>

                1. 本文介绍了在 Oracle 中连接和分组多行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  可能的重复:
                  如何检索 A、B 中的两列数据Oracle 格式

                  假设我有一张这样的表:

                  Suppose I have a table like this:

                  NAME          GROUP_NAME
                  name1         groupA
                  name2         groupB
                  name5         groupC
                  name4         groupA
                  name3         groupC
                  

                  我想要这样的结果:

                  GROUP_NAME     NAMES
                  groupA         name1,name4
                  groupB         name2
                  groupC         name3,name5
                  

                  如果表中只有一列,我可以通过执行以下操作来连接记录,但是在上下文中进行分组,我真的没有太多想法.

                  If there were only one column in the table, I could concatenate the records by doing the following, but with grouping in the context, I really don't have much idea.

                  连接一个列表:

                  SELECT names 
                  FROM (SELECT SYS_CONNECT_BY_PATH(names,' ') names, level
                        FROM name_table
                  
                        START WITH names = (SELECT names FROM name_table WHERE rownum = 1)
                        CONNECT BY PRIOR names < names
                        ORDER BY level DESC)
                        WHERE rownum = 1 
                  

                  更新:

                  我现在有一个使用 LISTAGG 的解决方案:

                  SELECT
                  group_name,
                  LISTAGG(name, ', ')
                  WITHIN GROUP (ORDER BY GROUP) "names"
                  FROM name_table
                  GROUP BY group_name
                  

                  对于 LISTAGG 不可用的情况,仍然对更通用"的解决方案感兴趣.

                  Still interested in a more "general" solution for cases when LISTAGG is not available.

                  推荐答案

                  考虑使用 LISTAGG 功能,以防您使用 11g:

                  Consider using LISTAGG function in case you're on 11g:

                  select grp, listagg(name,',') within group( order by name ) 
                    from name_table group by grp
                  

                  sqlFiddle

                  upd:如果您不是,请考虑使用分析:

                  upd: In case you're not, consider using analytics:

                  select grp,
                      ltrim(max(sys_connect_by_path
                         (name, ',' )), ',')
                          scbp
                    from (select name, grp,
                              row_number() over
                             (partition by grp
                              order by name) rn
                           from tab
                            )
                  start with rn = 1
                  connect by prior rn = rn-1
                  and prior grp = grp
                    group by grp
                    order by grp
                  

                  sqlFiddle

                  这篇关于在 Oracle 中连接和分组多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
                  SQL query to group by day(按天分组的 SQL 查询)
                  What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
                  MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
                  MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
                  Include missing months in Group By query(在 Group By 查询中包含缺失的月份)
                      <bdo id='gokT8'></bdo><ul id='gokT8'></ul>

                      <i id='gokT8'><tr id='gokT8'><dt id='gokT8'><q id='gokT8'><span id='gokT8'><b id='gokT8'><form id='gokT8'><ins id='gokT8'></ins><ul id='gokT8'></ul><sub id='gokT8'></sub></form><legend id='gokT8'></legend><bdo id='gokT8'><pre id='gokT8'><center id='gokT8'></center></pre></bdo></b><th id='gokT8'></th></span></q></dt></tr></i><div id='gokT8'><tfoot id='gokT8'></tfoot><dl id='gokT8'><fieldset id='gokT8'></fieldset></dl></div>
                    • <small id='gokT8'></small><noframes id='gokT8'>

                      <legend id='gokT8'><style id='gokT8'><dir id='gokT8'><q id='gokT8'></q></dir></style></legend>

                        <tbody id='gokT8'></tbody>
                      • <tfoot id='gokT8'></tfoot>