DA0-002 · Question #67
The human resources department wants to know the number of employees who earn $125,000 or more. However, the department is concerned about duplicates in the dataset. Given the following table: Which o
The correct answer is B. SELECT COUNT(DISTINCT Employee_ID) FROM Employee WHERE Salary >= 125000. To find the number of employees earning $125,000 or more while avoiding duplicates, the COUNT(DISTINCT Employee_ID) function is used. This function aggregates and counts only the unique employee identifiers that meet the specified salary criteria.
Question
The human resources department wants to know the number of employees who earn $125,000 or more. However, the department is concerned about duplicates in the dataset. Given the following table:
Which of the following SQL statements resolves this issue?
Options
- ASELECT DISTINCT Employee_ID FROM Employee WHERE Salary >= 125000
- BSELECT COUNT(DISTINCT Employee_ID) FROM Employee WHERE Salary >= 125000
- CSELECT DISTINCT Employee_ID FROM Employee WHERE Salary > 125000
- DSELECT COUNT(Employee_ID) FROM Employee WHERE Salary >= 125000
How the community answered
(36 responses)- A8% (3)
- B72% (26)
- C3% (1)
- D17% (6)
Why each option
To find the number of employees earning $125,000 or more while avoiding duplicates, the `COUNT(DISTINCT Employee_ID)` function is used. This function aggregates and counts only the unique employee identifiers that meet the specified salary criteria.
This statement selects a list of distinct `Employee_ID` values but does not return a count, which is what the human resources department requested.
The SQL statement `SELECT COUNT(DISTINCT Employee_ID) FROM Employee WHERE Salary >= 125000` correctly addresses both requirements. `COUNT(DISTINCT Employee_ID)` ensures that each unique employee is counted only once, effectively resolving any duplicate entries, and the `WHERE Salary >= 125000` clause filters for employees earning $125,000 or more.
This statement uses `Salary > 125000`, which excludes employees earning exactly $125,000, contradicting the requirement of "$125,000 or more." Additionally, it returns a list of IDs, not a count.
This statement uses `COUNT(Employee_ID)` without `DISTINCT`, meaning it would count all employee IDs that meet the salary criteria, including any duplicates, which goes against the department's concern about duplicates.
Concept tested: SQL COUNT DISTINCT aggregate function
Source: https://learn.microsoft.com/en-us/sql/t-sql/functions/count-transact-sql
Topics
Community Discussion
No community discussion yet for this question.