设为首页 - 加入收藏 PHP编程网 - PHP站长网 (http://www.52php.cn)- 电商,百科,编程,业界,移动互联,5G,云计算,站长网!
热搜: google 娱乐 服务 百度
当前位置: 首页 > 站长百科 > 正文

oracle sql选择具有GROUP BY和HAVING子句的语法

发布时间:2021-05-16 02:11 所属栏目:[站长百科] 来源:网络整理
导读:我一直在通过一些sql语法来研究oracle sql考试,我发现了一些令人困惑的东西 基于official引用,select语法如下: SELECT [ hint ] [ { { DISTINCT | UNIQUE } | ALL } ] select_list FROM { table_reference | join_clause | ( join_clause ) } [,{ table_r

我一直在通过一些sql语法来研究oracle sql考试,我发现了一些令人困惑的东西

基于official引用,select语法如下:

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.

【免责声明】本站内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。

推荐文章
热点阅读