小编poo*_*oja的帖子

别名在哪里和有什么区别

如果我中创建一个别名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)

这有效.为什么这样?

sql group-by having having-clause

6
推荐指数
1
解决办法
1763
查看次数

标签 统计

group-by ×1

having ×1

having-clause ×1

sql ×1