不包含group by属性的HAVING子句

问题描述 投票:0回答:1

使用

HAVING
子句而不提及
group by
中的属性是否正确?
例如:

select ncl 
from commande c, ligne_commande lc 
where c.nc = lc.nc
group by ncl
having count(nart) = ...

nart
属性未在
group by
中定义。

sql oracle select group-by having
1个回答
1
投票

having
子句中的术语必须是组的属性 - 即,您分组的列或聚合表达式。
count(nart)
是一个聚合项(组中非
null
nart
值的数量),因此在
having
子句中是完全合法的。

© www.soinside.com 2019 - 2024. All rights reserved.