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

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

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

        <bdo id='XPpCr'></bdo><ul id='XPpCr'></ul>
      <tfoot id='XPpCr'></tfoot>
    2. 逗号分隔值与 SQL 查询

      Comma Separated values with SQL Query(逗号分隔值与 SQL 查询)
      1. <i id='odfd8'><tr id='odfd8'><dt id='odfd8'><q id='odfd8'><span id='odfd8'><b id='odfd8'><form id='odfd8'><ins id='odfd8'></ins><ul id='odfd8'></ul><sub id='odfd8'></sub></form><legend id='odfd8'></legend><bdo id='odfd8'><pre id='odfd8'><center id='odfd8'></center></pre></bdo></b><th id='odfd8'></th></span></q></dt></tr></i><div id='odfd8'><tfoot id='odfd8'></tfoot><dl id='odfd8'><fieldset id='odfd8'></fieldset></dl></div>
      2. <legend id='odfd8'><style id='odfd8'><dir id='odfd8'><q id='odfd8'></q></dir></style></legend>
        <tfoot id='odfd8'></tfoot>

              <bdo id='odfd8'></bdo><ul id='odfd8'></ul>
                <tbody id='odfd8'></tbody>
            • <small id='odfd8'></small><noframes id='odfd8'>

              • 本文介绍了逗号分隔值与 SQL 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我的SQL表如下

                City_Code     Post_Code    Post_Code_Description
                100           A1           ABC
                100           C8           XYZ
                100           Z3           MNO
                200           D4           LMN
                300           E3           IJK
                300           B9           RST
                

                这是 city_code 和 Post_Code 之间的映射.一个 City_Code 有许多邮政编码.现在我想运行一个查询来获得类似以下内容

                It's a mapping between city_code and Post_Code. One City_Code has many Post Codes. Now i want to run a Query to get something like following

                City_Code     Post_Code    Post_Code_Description
                100           A1,C8,Z3     ABC,XYZ,MNO
                200           D4           LMN
                300           E3,B9        IJK,RST
                

                你能帮我处理一下这个 SQL 表吗

                Can you please help me with thisy SQL table is like following

                推荐答案

                试试这个:

                SELECT City_Code, 
                      Post_Code = 
                        STUFF((SELECT ', ' + Post_Code
                           FROM your_table b 
                           WHERE b.City_Code = a.City_Code 
                          FOR XML PATH('')), 1, 2, ''),
                      Post_Code_Description=
                        STUFF((SELECT ', ' + Post_Code_Description
                           FROM your_table b 
                           WHERE b.City_Code = a.City_Code 
                          FOR XML PATH('')), 1, 2, '')
                FROM your_table a
                GROUP BY City_Code
                

                这篇关于逗号分隔值与 SQL 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

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

                      <tbody id='Q53mh'></tbody>
                  1. <small id='Q53mh'></small><noframes id='Q53mh'>

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

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