加入收藏 | 设为首页 | 会员中心 | 我要投稿 辽源站长网 (https://www.0437zz.com/)- 云专线、云连接、智能数据、边缘计算、数据安全!
当前位置: 首页 > 站长百科 > 正文

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

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

我一直在通过一些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.

(编辑:辽源站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读