<small id='qmQMH'></small><noframes id='qmQMH'>

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

    1. <tfoot id='qmQMH'></tfoot>

        用于连接 Oracle 中多行列值的 SQL 查询

        时间:2023-07-18
        1. <i id='Y7i7y'><tr id='Y7i7y'><dt id='Y7i7y'><q id='Y7i7y'><span id='Y7i7y'><b id='Y7i7y'><form id='Y7i7y'><ins id='Y7i7y'></ins><ul id='Y7i7y'></ul><sub id='Y7i7y'></sub></form><legend id='Y7i7y'></legend><bdo id='Y7i7y'><pre id='Y7i7y'><center id='Y7i7y'></center></pre></bdo></b><th id='Y7i7y'></th></span></q></dt></tr></i><div id='Y7i7y'><tfoot id='Y7i7y'></tfoot><dl id='Y7i7y'><fieldset id='Y7i7y'></fieldset></dl></div>
          • <tfoot id='Y7i7y'></tfoot>
              <tbody id='Y7i7y'></tbody>

            <small id='Y7i7y'></small><noframes id='Y7i7y'>

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

                • <bdo id='Y7i7y'></bdo><ul id='Y7i7y'></ul>
                  本文介绍了用于连接 Oracle 中多行列值的 SQL 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  是否可以构造 SQL 来连接来自多行?

                  以下是一个例子:

                  表A

                  <前>PID一种乙C

                  表 B

                  <前>PID 序列描述A 1 有A 2 不错一个3天.B 1 干得漂亮.C 1 是C 2 我们可以C 3 做C 4 这个作品!

                  SQL 的输出应该是 -

                  <前>PID 描述A 祝你有美好的一天.B 干得好.C 是的,我们可以完成这项工作!

                  所以基本上输出表的 Desc 列是表 B 中 SEQ 值的串联?

                  对 SQL 有任何帮助吗?

                  解决方案

                  根据您的版本,有几种方法 - 请参阅 关于字符串聚合技术的 oracle 文档.一个很常见的方法是使用 LISTAGG:

                  SELECT pid, LISTAGG(Desc, ' ') WITHIN GROUP (ORDER BY seq) AS 描述FROM B GROUP BY pid;

                  然后加入A来挑选你想要的pids.

                  注意:开箱即用,LISTAGG 仅适用于 VARCHAR2 列.

                  Would it be possible to construct SQL to concatenate column values from multiple rows?

                  The following is an example:

                  Table A

                  PID
                  A
                  B
                  C
                  

                  Table B

                  PID   SEQ    Desc
                  
                  A     1      Have
                  A     2      a nice
                  A     3      day.
                  B     1      Nice Work.
                  C     1      Yes
                  C     2      we can 
                  C     3      do 
                  C     4      this work!
                  

                  Output of the SQL should be -

                  PID   Desc
                  A     Have a nice day.
                  B     Nice Work.
                  C     Yes we can do this work!
                  

                  So basically the Desc column for out put table is a concatenation of the SEQ values from Table B?

                  Any help with the SQL?

                  解决方案

                  There are a few ways depending on what version you have - see the oracle documentation on string aggregation techniques. A very common one is to use LISTAGG:

                  SELECT pid, LISTAGG(Desc, ' ') WITHIN GROUP (ORDER BY seq) AS description
                  FROM B GROUP BY pid;
                  

                  Then join to A to pick out the pids you want.

                  Note: Out of the box, LISTAGG only works correctly with VARCHAR2 columns.

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

                  <tfoot id='rpKXg'></tfoot>
                    <tbody id='rpKXg'></tbody>

                  • <bdo id='rpKXg'></bdo><ul id='rpKXg'></ul>

                  • <legend id='rpKXg'><style id='rpKXg'><dir id='rpKXg'><q id='rpKXg'></q></dir></style></legend>

                    <small id='rpKXg'></small><noframes id='rpKXg'>

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