<small id='7AY1a'></small><noframes id='7AY1a'>

  • <legend id='7AY1a'><style id='7AY1a'><dir id='7AY1a'><q id='7AY1a'></q></dir></style></legend>

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

        使用 Oracle LISTAGG 函数消除重复项

        时间:2023-06-24
        • <bdo id='jsmpC'></bdo><ul id='jsmpC'></ul>

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

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

                <tbody id='jsmpC'></tbody>

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

                • 本文介绍了使用 Oracle LISTAGG 函数消除重复项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  可能的重复:
                  oracle 中的 LISTAGG 返回不同的值

                  我正在使用 Oracle LISTAGG 函数,但在我返回的名称列表中,我实际上希望消除重复项并只返回不同的值.

                  I am using Oracle LISTAGG function but within my list of returned names I actually would like to eliminate duplicates and only return distinct values.

                  我的查询是这样的:

                  select a.id,
                         a.change_id,
                         LISTAGG(b.name, ',') WITHIN GROUP (ORDER BY b.name) AS "Product Name", 
                  from   table_a a,
                         table_b b
                  where  a.id = 1
                  and    b.change_id = c.change_id
                  group by a.id, a.change_id
                  

                  目前正在返回(只显示一条记录):

                  At the moment, it is returning (just showing one record):

                  1    1   NameA, NameA, NameB, NameC, NameD, Name D
                  

                  我希望返回的是:

                  1    1   NameA, NameB, NameC, Name D
                  

                  推荐答案

                  由于评论中的链接答案没有提供我的解决方案,我还是会发布.

                  As the linked answers in the comment don't provide my flavor of solution, I'll post it anyway.

                  我只会使用带有虚拟数据的 table_b 来展示概念,您可以轻松添加您的连接等:

                  I'll only use table_b with dummy data to show the concept, you can easily add your join etc.:

                  with table_b as ( -- dummy data
                   select 'name'||mod(level,3) name
                          ,mod(level,3) id
                     from dual
                    connect by level < 10
                   union all
                   select 'name'||mod(level,2) name
                          ,mod(level,3) id
                     from dual
                    connect by level < 10
                  )
                  select id
                        ,RTRIM (
                                XMLAGG (
                                        XMLELEMENT (E,XMLATTRIBUTES (name|| ',' AS "Seg")
                                        )
                                       ORDER BY name ASC
                                ).EXTRACT ('./E[not(@Seg = preceding-sibling::E/@Seg)]/@Seg'),
                                ','
                               ) AS "Product Name"
                         ,LISTAGG(b.name, ',') WITHIN GROUP (ORDER BY b.name) AS "Product Name with dups"
                    from table_b b
                  group by id;
                  

                  (想法取自 https://forums.oracle.com/forums/thread.jspa?messageID=9634767&tstart=0#9943367)

                  这篇关于使用 Oracle LISTAGG 函数消除重复项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:获取信封.即重叠的时间跨度 下一篇:如何在 sqlite 中使用 ROW_NUMBER

                  相关文章

                • <legend id='o0nbn'><style id='o0nbn'><dir id='o0nbn'><q id='o0nbn'></q></dir></style></legend>
                  <tfoot id='o0nbn'></tfoot>

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

                    1. <small id='o0nbn'></small><noframes id='o0nbn'>