<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 组合/连接一列

        GROUP BY to combine/concat a column(GROUP BY 组合/连接一列)
        <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 组合/连接一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 查询中包含缺失的月份)

                  <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>

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

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