Reprint: SQL statements use aliases in where to judge conditions

Source: Internet
Author: User
Tags aliases

Original address: http://www.cnblogs.com/dwfbenben/p/3307941.html

When we use an expression as a column of output, we cannot use that column directly in the Where condition as a criterion. For example, the following SQL statement:select id (C1 + C2 ) as s from t1  where s > 100 & nbsp SQL Server Error:      Select Id (C1 + c2) as s from t1  where (C1 + c2) >

The

is no problem.   But when the expression is complex, it is cumbersome.     is there a way to use such a column name in the Where?   or is there any other way to solve such problems? Workaround:

sql code copy code
 select t2. *from  (select id (C1 + c2) as C from t1 T2 where C > + --or select t2.< span class= "C" >*from  (select id, C  = C1+c2 from t1 T2where C > 100
                                                  

                        because column aliases cannot be used directly in the where statement, we need to wrap the SQL statement                         in Oracle, referencing column aliases in a WHERE clause can be an error , what is this for?                         because: The order of execution of the SELECT statement                         1. From Statement                         2. Where statement (binding condition)                         3. Start with statement &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&Nbsp;           4. Connect by Statement                         5. Where statement                         6. GROUP BY Statement                         7. Having statements                         8. Model Statement                         9. SELECT statement                         10. Union, minus, intersect, etc. set calculus calculus &NBSP;&NBSP;&NBSP;&NBSP;&NBSp;                  11. ORDER BY statement

Reprint: SQL statements use aliases in where to determine conditions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.