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

    <tfoot id='8nH1b'></tfoot>

      <bdo id='8nH1b'></bdo><ul id='8nH1b'></ul>

      了解 Oracle 别名 - 为什么除非包含在第二个查询中,否则查询中无法识别别名?

      Understanding Oracle aliasing - why isn#39;t an alias not recognized in a query unless wrapped in a second query?(了解 Oracle 别名 - 为什么除非包含在第二个查询中,否则查询中无法识别别名?)
      <legend id='NKjtC'><style id='NKjtC'><dir id='NKjtC'><q id='NKjtC'></q></dir></style></legend>
    1. <small id='NKjtC'></small><noframes id='NKjtC'>

        <tfoot id='NKjtC'></tfoot>
          • <bdo id='NKjtC'></bdo><ul id='NKjtC'></ul>

                  <tbody id='NKjtC'></tbody>
              1. <i id='NKjtC'><tr id='NKjtC'><dt id='NKjtC'><q id='NKjtC'><span id='NKjtC'><b id='NKjtC'><form id='NKjtC'><ins id='NKjtC'></ins><ul id='NKjtC'></ul><sub id='NKjtC'></sub></form><legend id='NKjtC'></legend><bdo id='NKjtC'><pre id='NKjtC'><center id='NKjtC'></center></pre></bdo></b><th id='NKjtC'></th></span></q></dt></tr></i><div id='NKjtC'><tfoot id='NKjtC'></tfoot><dl id='NKjtC'><fieldset id='NKjtC'></fieldset></dl></div>
                本文介绍了了解 Oracle 别名 - 为什么除非包含在第二个查询中,否则查询中无法识别别名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有一个问题

                
                SELECT COUNT(*) AS "CNT",
                       imei
                FROM   devices  
                

                执行得很好.我想用 WHERE 语句进一步限制查询.(人为)合乎逻辑的下一步是按以下方式修改查询:

                which executes just fine. I want to further restrict the query with a WHERE statement. The (humanly) logical next step is to modify the query followingly:

                
                SELECT COUNT(*) AS "CNT",
                       imei
                FROM   devices
                WHERE  CNT > 1 
                

                然而,这会导致错误消息ORA-00904:CNT":标识符无效.出于某种原因,将查询包装在另一个查询中会产生所需的结果:

                However, this results in a error message ORA-00904: "CNT": invalid identifier. For some reason, wrapping the query in another query produces the desired result:

                
                SELECT *
                FROM   (SELECT COUNT(*) AS "CNT",
                               imei
                        FROM   devices
                        GROUP  BY imei)
                WHERE  CNT > 1  
                

                为什么 Oracle 在第二个查询中无法识别别名CNT"?

                Why does Oracle not recognize the alias "CNT" in the second query?

                推荐答案

                简单的答案是 AS 子句定义了结果中将调用的列,与查询本身.

                The simple answer is that the AS clause defines what the column will be called in the result, which is a different scope than the query itself.

                在您的示例中,使用 HAVING 子句效果最佳:

                In your example, using the HAVING clause would work best:

                SELECT COUNT(*) AS "CNT",
                       imei
                FROM   devices
                GROUP  BY imei
                HAVING COUNT(*) > 1
                

                这篇关于了解 Oracle 别名 - 为什么除非包含在第二个查询中,否则查询中无法识别别名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                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='sC06F'></small><noframes id='sC06F'>

                      <tbody id='sC06F'></tbody>
                    <legend id='sC06F'><style id='sC06F'><dir id='sC06F'><q id='sC06F'></q></dir></style></legend>
                      <bdo id='sC06F'></bdo><ul id='sC06F'></ul>
                      <tfoot id='sC06F'></tfoot>

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