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

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

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

  1. <tfoot id='cT2Qu'></tfoot>

    1. <legend id='cT2Qu'><style id='cT2Qu'><dir id='cT2Qu'><q id='cT2Qu'></q></dir></style></legend>

      为什么 Oracle SQL 不允许我们在 GROUP BY 子句中使用列别名?

      Why doesn#39;t Oracle SQL allow us to use column aliases in GROUP BY clauses?(为什么 Oracle SQL 不允许我们在 GROUP BY 子句中使用列别名?)
    2. <i id='swr8y'><tr id='swr8y'><dt id='swr8y'><q id='swr8y'><span id='swr8y'><b id='swr8y'><form id='swr8y'><ins id='swr8y'></ins><ul id='swr8y'></ul><sub id='swr8y'></sub></form><legend id='swr8y'></legend><bdo id='swr8y'><pre id='swr8y'><center id='swr8y'></center></pre></bdo></b><th id='swr8y'></th></span></q></dt></tr></i><div id='swr8y'><tfoot id='swr8y'></tfoot><dl id='swr8y'><fieldset id='swr8y'></fieldset></dl></div>

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

          <tfoot id='swr8y'></tfoot>
                  <tbody id='swr8y'></tbody>

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

                <legend id='swr8y'><style id='swr8y'><dir id='swr8y'><q id='swr8y'></q></dir></style></legend>
                本文介绍了为什么 Oracle SQL 不允许我们在 GROUP BY 子句中使用列别名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                这是我在编写 SQL 查询时通常面临的情况.我认为在 GROUP BY 表达式中编写整列(例如长 case 表达式、长参数求和函数)而不是别名会使查询更长且可读性更低.为什么 Oracle SQL 不允许我们在 GROUP BY 子句中使用列别名?这背后一定有重要的原因.

                This is a situation I'm generally facing while writing SQL queries. I think that writing the whole column (e.g. long case expressions, sum functions with long parameters) instead of aliases in GROUP BY expressions makes the query longer and less readable. Why doesn't Oracle SQL allow us to use the column aliases in GROUP BY clause? There must be an important reason behind it.

                推荐答案

                它不仅仅是 Oracle SQL,事实上我相信它符合 ANSI SQL 标准(尽管我没有参考).原因是 SELECT 子句在 GROUP BY 子句之后进行逻辑处理,因此在 GROUP BY 完成时,别名还不存在.

                It isn't just Oracle SQL, in fact I believe it is conforming to the ANSI SQL standard (though I don't have a reference for that). The reason is that the SELECT clause is logically processed after the GROUP BY clause, so at the time the GROUP BY is done the aliases don't yet exist.

                也许这个有点荒谬的例子有助于澄清问题和 SQL 避免的歧义:

                Perhaps this somewhat ridiculous example helps clarify the issue and the ambiguity that SQL is avoiding:

                SQL> select job as sal, sum(sal) as job
                  2  from scott.emp
                  3  group by job;
                
                SAL              JOB
                --------- ----------
                ANALYST         6000
                CLERK           4150
                MANAGER         8275
                PRESIDENT       5000
                SALESMAN        5600
                

                这篇关于为什么 Oracle SQL 不允许我们在 GROUP BY 子句中使用列别名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                How to delete duplicate records in mysql database?(如何删除mysql数据库中的重复记录?)
                Python Pandas write to sql with NaN values(Python Pandas 使用 NaN 值写入 sql)
                MySQL Insert amp; Joins(MySQL 插入 amp;加入)
                MySQL concat() to create column names to be used in a query?(MySQL concat() 创建要在查询中使用的列名?)
                NodeJS responded MySQL timezone is different when I fetch directly from MySQL(当我直接从 MySQL 获取时,NodeJS 响应 MySQL 时区不同)
                WHERE datetime older than some time (eg. 15 minutes)(WHERE 日期时间早于某个时间(例如 15 分钟))
              • <tfoot id='6cuzq'></tfoot>

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

                    <small id='6cuzq'></small><noframes id='6cuzq'>

                      <bdo id='6cuzq'></bdo><ul id='6cuzq'></ul>
                      • <legend id='6cuzq'><style id='6cuzq'><dir id='6cuzq'><q id='6cuzq'></q></dir></style></legend>