gpt4 book ai didi

sql - oracle sql 选择语法与 GROUP BY 和 HAVING 子句

转载 作者:行者123 更新时间:2023-12-04 19:07:50 24 4
gpt4 key购买 nike

我一直在通过一些 sql 语法来学习 oracle sql 考试,我发现一些相当困惑的东西

基于 official引用,选择语法如下:

SELECT
[ hint ]
[ { { DISTINCT | UNIQUE } | ALL } ]
select_list
FROM { table_reference | join_clause | ( join_clause ) }
[ , { table_reference | join_clause | (join_clause) } ] ...
[ where_clause ]
[ hierarchical_query_clause ]
[ group_by_clause ]
[ HAVING condition ]
[ model_clause ]

基于此,您不能在 GROUP BY 子句之前使用 HAVING 子句。但是,如果我要在测试服务器中执行以下 sql:
select 
department_id , count (*)
from
employees
having
count(*) > 6
group by
department_id ;

它不会产生语法错误,有人可以帮忙解释一下吗?我不喜欢认为引用文档是错误的,但如果是这样,我需要一些确认。

最佳答案

如前所述 here :

Use the HAVING clause to restrict the groups of returned rows to those groups for which the specified condition is TRUE. If you omit this clause, then the database returns summary rows for all groups.

Specify GROUP BY and HAVING after the where_clause and hierarchical_query_clause. If you specify both GROUP BY and HAVING, then they can appear in either order.

关于sql - oracle sql 选择语法与 GROUP BY 和 HAVING 子句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20188862/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com