Select oracle sql syntax with GROUP BY and HAVING clause

I walked through some sql syntax to study for an Oracle exam, I found something rather confusing

based on official links, the syntax of the selection is as follows:

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 ]

based on this, you cannot have a HAVING clause before a GROUP BY clause. However, if I were to execute the following sql on a test server:

select 
   department_id , count (*)      
from 
    employees 
having 
    count(*) > 6 
group by 
    department_id ; 

it does not create a syntax error, can someone explain this? I don't like to think that the referenced documents are wrong, but if so, I need confirmation.

+4
source share
1 answer

As indicated here :

HAVING, , . , .

GROUP BY HAVING where_clause hierarchical_query_clause. GROUP BY, HAVING, , .

+5

All Articles