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

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

          <bdo id='FTRjH'></bdo><ul id='FTRjH'></ul>
      2. <small id='FTRjH'></small><noframes id='FTRjH'>

        在 WHERE 子句中使用别名

        Using an Alias in a WHERE clause(在 WHERE 子句中使用别名)
      3. <tfoot id='vQWLa'></tfoot>
      4. <legend id='vQWLa'><style id='vQWLa'><dir id='vQWLa'><q id='vQWLa'></q></dir></style></legend>
        <i id='vQWLa'><tr id='vQWLa'><dt id='vQWLa'><q id='vQWLa'><span id='vQWLa'><b id='vQWLa'><form id='vQWLa'><ins id='vQWLa'></ins><ul id='vQWLa'></ul><sub id='vQWLa'></sub></form><legend id='vQWLa'></legend><bdo id='vQWLa'><pre id='vQWLa'><center id='vQWLa'></center></pre></bdo></b><th id='vQWLa'></th></span></q></dt></tr></i><div id='vQWLa'><tfoot id='vQWLa'></tfoot><dl id='vQWLa'><fieldset id='vQWLa'></fieldset></dl></div>
            <tbody id='vQWLa'></tbody>

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

                • <small id='vQWLa'></small><noframes id='vQWLa'>

                  本文介绍了在 WHERE 子句中使用别名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个查询,旨在向我显示表 A 中最近没有足够更新的任何行.(每行应在month_no"之后的 2 个月内更新.):

                  I have a query which is meant to show me any rows in table A which have not been updated recently enough. (Each row should be updated within 2 months after "month_no".):

                  SELECT A.identifier
                       , A.name
                       , TO_NUMBER(DECODE( A.month_no
                               , 1, 200803 
                               , 2, 200804 
                               , 3, 200805 
                               , 4, 200806 
                               , 5, 200807 
                               , 6, 200808 
                               , 7, 200809 
                               , 8, 200810 
                               , 9, 200811 
                               , 10, 200812 
                               , 11, 200701 
                               , 12, 200702
                               , NULL)) as MONTH_NO
                       , TO_NUMBER(TO_CHAR(B.last_update_date, 'YYYYMM')) as UPD_DATE
                    FROM table_a A
                       , table_b B
                   WHERE A.identifier = B.identifier
                     AND MONTH_NO > UPD_DATE
                  

                  WHERE 子句中的最后一行导致ORA-00904 无效标识符"错误.不用说,我不想在 WHERE 子句中重复整个 DECODE 函数.有什么想法吗?(修复和变通方法都被接受...)

                  The last line in the WHERE clause causes an "ORA-00904 Invalid Identifier" error. Needless to say, I don't want to repeat the entire DECODE function in my WHERE clause. Any thoughts? (Both fixes and workarounds accepted...)

                  推荐答案

                  这不是直接可能的,因为按时间顺序,WHERE 发生在 before SELECT 之前,它总是执行链中的最后一步.

                  This is not possible directly, because chronologically, WHERE happens before SELECT, which always is the last step in the execution chain.

                  您可以对其进行子选择和过滤:

                  You can do a sub-select and filter on it:

                  SELECT * FROM
                  (
                    SELECT A.identifier
                      , A.name
                      , TO_NUMBER(DECODE( A.month_no
                        , 1, 200803 
                        , 2, 200804 
                        , 3, 200805 
                        , 4, 200806 
                        , 5, 200807 
                        , 6, 200808 
                        , 7, 200809 
                        , 8, 200810 
                        , 9, 200811 
                        , 10, 200812 
                        , 11, 200701 
                        , 12, 200702
                        , NULL)) as MONTH_NO
                      , TO_NUMBER(TO_CHAR(B.last_update_date, 'YYYYMM')) as UPD_DATE
                    FROM table_a A
                      , table_b B
                    WHERE A.identifier = B.identifier
                  ) AS inner_table
                  WHERE 
                    MONTH_NO > UPD_DATE
                  

                  从评论中移出有趣的信息:

                  Interesting bit of info moved up from the comments:

                  应该不会影响性能.Oracle 不需要物化应用外部之前的内部查询条件——甲骨文会考虑在内部转换此查询并将谓词下推到内部查询,如果有成本就会这样做有效的.– 贾斯汀洞穴

                  There should be no performance hit. Oracle does not need to materialize inner queries before applying outer conditions -- Oracle will consider transforming this query internally and push the predicate down into the inner query and will do so if it is cost effective. – Justin Cave

                  这篇关于在 WHERE 子句中使用别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 分钟))

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

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

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

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