<tfoot id='EqlAy'></tfoot>
  • <small id='EqlAy'></small><noframes id='EqlAy'>

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

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

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

        将两行合并为一行,同时替换空值

        Merging two rows to one while replacing null values(将两行合并为一行,同时替换空值)

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

            <tbody id='KbmhI'></tbody>

                  本文介绍了将两行合并为一行,同时替换空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  假设我有以下数据库表

                  Name | Nickname | ID
                  ----------------------
                  Joe    Joey       14
                  Joe    null       14
                  

                  现在我想做一个选择语句,将这两列合并为一,同时替换空值.结果应该是这样的:

                  Now I want to do a select statement that merges these two columns to one while replacing the null values. The result should look like this:

                  Joe, Joey, 14
                  

                  哪个 sql 语句管理这个(如果可能的话)?

                  Which sql statement manages this (if it's even possible)?

                  推荐答案

                  最简单的解决方案:

                  SQL> select * from t69
                    2  /
                  
                  NAME       NICKNAME           ID
                  ---------- ---------- ----------
                  Joe        Joey               14
                  Joe                           14
                  Michael                       15
                             Mick               15
                             Mickey             15
                  
                  SQL> select max(name) as name
                    2         , max(nickname) as nickname
                    3         , id
                    4  from t69
                    5  group by id
                    6  /
                  
                  NAME       NICKNAME           ID
                  ---------- ---------- ----------
                  Joe        Joey               14
                  Michael    Mickey             15
                  
                  SQL>
                  

                  如果您有 11gR2,您可以使用 新的-奇怪的 LISTAGG() 函数 但除此之外,将上述语句包装在连接 NAME 和 NICKNAME 列的 SELECT 中很简单.

                  If you have 11gR2 you could use the new-fangled LISTAGG() function but otherwise it is simple enough to wrap the above statement in a SELECT which concatenates the NAME and NICKNAME columns.

                  这篇关于将两行合并为一行,同时替换空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 查询中包含缺失的月份)
                1. <i id='0OLx4'><tr id='0OLx4'><dt id='0OLx4'><q id='0OLx4'><span id='0OLx4'><b id='0OLx4'><form id='0OLx4'><ins id='0OLx4'></ins><ul id='0OLx4'></ul><sub id='0OLx4'></sub></form><legend id='0OLx4'></legend><bdo id='0OLx4'><pre id='0OLx4'><center id='0OLx4'></center></pre></bdo></b><th id='0OLx4'></th></span></q></dt></tr></i><div id='0OLx4'><tfoot id='0OLx4'></tfoot><dl id='0OLx4'><fieldset id='0OLx4'></fieldset></dl></div>
                  • <small id='0OLx4'></small><noframes id='0OLx4'>

                    • <bdo id='0OLx4'></bdo><ul id='0OLx4'></ul>
                      <legend id='0OLx4'><style id='0OLx4'><dir id='0OLx4'><q id='0OLx4'></q></dir></style></legend>
                      <tfoot id='0OLx4'></tfoot>
                        <tbody id='0OLx4'></tbody>