If I create an alias in the select clause then I cannot use it in the where clause because according to the order of execution of sql queries where comes before select.
But I can create an alias in the select clause and use it in a having clause though having comes before select.
Why is it so?
Ex:
select type, (case when number>25 then 1 else 0 end) inc
from animals
where inc='1';
this wont work. But,
select type, (case when number>25 then 1 else 0 end) inc
from animals
having inc='1';
This works. Why so?