1z0-071 Exam QuestionsBrowse all questions from this exam

1z0-071 Exam - Question 47


Examine the description of the EMPLOYEES table:

Which statement will fail?

A.

B.

C.

D.

Show Answer
Correct Answer:

The only clause in a SQL statement that may include aggregate functions, such as COUNT(*), is the HAVING clause, and they must be used after the GROUP BY clause if the query includes a grouped aggregation. What is more, semicolons are typically used to signify the end of a SQL statement and would not generally indicate correctness or errors within a SQL query itself. Statements A, B, and C will fail for different reasons related to their structure and placement of clauses. In statement A, usage of an aggregate function, COUNT(*), directly within a WHERE clause is syntactically incorrect, as the WHERE clause cannot handle aggregate functions. Statements B and C misplace the HAVING clause relative to their other components, failing generally due to SQL syntax rules. Therefore, D is the appropriate answer, as it employs WHERE for the initial condition, groups appropriately, and applies HAVING for aggregated filtering after the grouped data is espoused.

Discussion

11 comments
Sign in to comment
MZEnuovazelanda
Sep 7, 2022

It's a mess! the first three are incorrect for the semicolon

darkma
Sep 26, 2023

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.

NSilva
May 1, 2024

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.

karols32
May 5, 2023

Don't pay attention about semicolon and the answer is A. Order of HAVING and GROUP BY doesn't matter. WHERE is not required in statement.

fgramos
Jun 11, 2023

D is the right answer. Works fine and AB and C are incorrect by semicolon

yanoolthecool
Jul 27, 2023

Agreed, that is if we assume the question is 'which statement will NOT fail'

zouve
Jul 5, 2023

A if you correct the semicolon to each and every query A the one that is failing with ORA-00934: group function is not allowed here

JCKOMI
Dec 23, 2022

A IS NOT correct for semicolon and also count is not applied to where clause

Ronit_8055
Jan 29, 2023

ABC are incorrect for semicolon and even for HVAING should comes after GROUP BY clause.

TheOracleWasTaken
Aug 2, 2023

I think it works regardless, probably not correct but it works

Orxan_H
Apr 19, 2023

A B are incorrect answers

MIGHTYSTUNNERS
May 1, 2024

C is wrong Because HAVING Clause come under group by clause

m_darwish
May 22, 2024

Ignore semicolon , A will fail .

alelejaja
May 29, 2024

A is the correct answer