'I am trying to filter an alias column, which I know it wont work in the WHERE clause. I need to filter the YEARS >15
select department_id, last_name, round(((sysdate-hire_date)/30)/12, 0) as YEARS
from employees
where YEARS >15;
Solution 1:[1]
One option is to repeat the round expression and also you can use DATEDIFF which is another option.
SELECT department_id, last_name,
ROUND(((SYSDATE - hire_date) / 30) / 12, 0) AS YEARS
FROM employees
Where DATEDIFF(year, hire_date, getdate()) > 15
Solution 2:[2]
Thank you guys, I came up with a resolution this morning
select department_id, sum(salary) as "Summary"
from employees
where round(((sysdate-hire_date)/30)/12, 0)>15
group by department_id
order by department_id;
Solution 3:[3]
this is the right code
select department_id, sum(salary) as "Summary" from employees where round(((sysdate-hire_date)/30)/12, 0)>15 group by department_id order by department_id;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Damini Suthar |
| Solution 2 | Chris Catignani |
| Solution 3 | Zori Kotzeva |
