我有一个统计组的SQL,但我想说在计数大于1的地方,有人能帮助我吗,因为它目前不起作用?
select Code, Qty, Count(Qty) from Product where ItemName = 'Banana'
and Count(Qty) > 1
Group by Code, Qty order by 3 desc
发布于 2017-01-16 19:12:35
您应该将此条件放入HAVING
-clause中:
select Code, Qty, Count(Qty) Qty
from Product
where ItemName = 'Banana'
Group by Code
having count(Qty) > 1
order by 3 desc
HAVING
在GROUP BY
之后求值,而WHERE
在前面求值,这意味着WHERE
-clauses将根据记录级进行过滤,而HAVING
-clauses将根据聚合进行过滤。
有关更详细的解释,请查看SQL - having VS where
https://stackoverflow.com/questions/41675073
复制相似问题