如果我中创建一个别名select子句然后我不能在使用where条款,因为根据SQL查询的执行顺序where之前来select.
但我可以创建在一个别名select子句和它的使用having条款,虽然having来之前select.
为什么会这样?
例如:
select type, (case when number>25 then 1 else 0 end) inc
from animals
where inc='1';
Run Code Online (Sandbox Code Playgroud)
这不行.但,
select type, (case when number>25 then 1 else 0 end) inc
from animals
having inc='1';
Run Code Online (Sandbox Code Playgroud)
这有效.为什么这样?