IS it possible to reference an alias in the select statement?
For example (and this does not work):
SELECT salary/52 AS “Weekly Salary”, “Weekly Salary” - 2
FROM EMPLOYEES
IS it possible to reference an alias in the select statement?
For example (and this does not work):
SELECT salary/52 AS “Weekly Salary”, “Weekly Salary” - 2
FROM EMPLOYEES
No you can’t. The “alias” as you’re using it is only the column heading in SQLplus. Your statement would have to be run as follows:
SELECT salary/52 “weekly Salary”, (salary/52) - 2 “Some othe column name”
from employees
/
However, using an alias in a sub-query allows you to reference it as a pseudo-column in the outer query:
select "Weekly Salary",
"Weekly Salary" * .05 as "Weekly Bonus"
from (Select salary/52 as "Weekly Salary" from employee2)
You need the double quotes in the outer query because “Weekly Salary” has a space in it. This makes it case-sensitive as well. If you had aliased it as “WEEKLY_SALARY” then you could refer to it as weekly_salary in the outer query.