How I can make/declare/define a derived column in select query and then use it in where clause?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
To define a column in an SQL query, you can use pretty much any SQL operation that returns a single value (including select statements). Here are some examples:
From my experience, if you want to use a derived column in a select query, then you must define the column as part of an inner select. Here is an example:
Another alternative is use the calculation within the where clause itself:
If you are performing a count(*) operation, then you can also leverage the HAVING clause: