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

          <bdo id='U5eGO'></bdo><ul id='U5eGO'></ul>
      1. <legend id='U5eGO'><style id='U5eGO'><dir id='U5eGO'><q id='U5eGO'></q></dir></style></legend>

        <tfoot id='U5eGO'></tfoot>
      2. <small id='U5eGO'></small><noframes id='U5eGO'>

      3. GROUP BY 组合/连接一列

        时间:2023-07-17
        <i id='2RpPp'><tr id='2RpPp'><dt id='2RpPp'><q id='2RpPp'><span id='2RpPp'><b id='2RpPp'><form id='2RpPp'><ins id='2RpPp'></ins><ul id='2RpPp'></ul><sub id='2RpPp'></sub></form><legend id='2RpPp'></legend><bdo id='2RpPp'><pre id='2RpPp'><center id='2RpPp'></center></pre></bdo></b><th id='2RpPp'></th></span></q></dt></tr></i><div id='2RpPp'><tfoot id='2RpPp'></tfoot><dl id='2RpPp'><fieldset id='2RpPp'></fieldset></dl></div>
            <bdo id='2RpPp'></bdo><ul id='2RpPp'></ul>
            • <small id='2RpPp'></small><noframes id='2RpPp'>

              • <tfoot id='2RpPp'></tfoot>
                  <tbody id='2RpPp'></tbody>

                  <legend id='2RpPp'><style id='2RpPp'><dir id='2RpPp'><q id='2RpPp'></q></dir></style></legend>
                  本文介绍了GROUP BY 组合/连接一列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个表格如下:

                  ID  User  Activity  PageURL  
                   1  Me    act1      ab     
                   2  Me    act1      cd     
                   3  You   act2      xy     
                   4  You   act2      st
                  

                  我想按用户和活动分组,这样我最终会得到类似的结果:

                  I want to group by User and Activity such that I end up with something like:

                  User  Activity  PageURL  
                  Me    act1      ab, cd     
                  You   act2      xy, st
                  

                  如您所见,PageURL 列组合在一起,并根据分组由逗号分隔.

                  As you can see, the column PageURL is combined together separated by a comma based on the group by.

                  非常感谢您的指点和建议.

                  Would really appreciate any pointers and advice.

                  推荐答案

                  SELECT
                       [User], Activity,
                       STUFF(
                           (SELECT DISTINCT ',' + PageURL
                            FROM TableName
                            WHERE [User] = a.[User] AND Activity = a.Activity
                            FOR XML PATH (''))
                            , 1, 1, '')  AS URLList
                  FROM TableName AS a
                  GROUP BY [User], Activity
                  

                  • SQLFiddle 演示
                  • 这篇关于GROUP BY 组合/连接一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:用于在 SQL Server 中存储 ip 地址的数据类型 下一篇:SQL Server 转义下划线

                  相关文章

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

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

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

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