The first query is syntactically incorrect. You cannot use the COUNT function in the WHERE clause.
The second query is also incorrect. The HAVING clause is used to filter the results of an aggregation, and it should be used after the GROUP BY clause, not after the WHERE clause.
The third query is also incorrect for the same reason as the second one. The HAVING clause should come after the GROUP BY clause.
The fourth query is correct and will work as expected. It filters rows where the department_id is not equal to 90 using the WHERE clause, groups the remaining rows by department_id, and then applies the HAVING clause to count the rows within each group and filter out groups where the count is greater than or equal to 3.
I tried it out in Oracle's Apex (Db v19C), using a data set from the internet.
SELECT id
FROM TITANIC
HAVING ID = 1
GROUP BY ID;
It does not affect the result if you use HAVING and GROUP BY in a different position from one to another.
It's a mess! the first three are incorrect for the semicolon
upvoted 3 times
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
darkma
Highly Voted 8 months, 2 weeks agoNSilva
1 month, 1 week agoalelejaja
Most Recent 1 week, 5 days agom_darwish
2 weeks, 5 days agoMIGHTYSTUNNERS
1 month, 1 week agozouve
11 months, 1 week agofgramos
1 year agoyanoolthecool
10 months, 2 weeks agokarols32
1 year, 1 month agoOrxan_H
1 year, 1 month agoRonit_8055
1 year, 4 months agoTheOracleWasTaken
10 months, 2 weeks agoJCKOMI
1 year, 5 months agoMZEnuovazelanda
1 year, 9 months ago