A data analyst receives a request for the current employee head count and runs the following SQL statement:
SELECT COUNT(EMPLOYEE_ID) FROM JOBS
The returned head count is higher than expected because employees can have multiple jobs. Which of the following should return an accurate employee head count?
This question falls under the Data Analysis domain of CompTIA Data+ DA0-002, which involves using SQL queries to analyze data and address issues like duplicates in datasets. The issue here is that the initial query counts all instances of EMPLOYEE_ID in the JOBS table, but employees can have multiple jobs, leading to an inflated head count. The goal is to count unique employees.
SELECT JOB_TYPE, COUNT DISTINCT(EMPLOYEE_ID) FROM JOBS (Option A): This query is syntactically incorrect because COUNT DISTINCT(EMPLOYEE_ID) should use parentheses as COUNT(DISTINCT EMPLOYEE_ID). It also groups by JOB_TYPE, which is unnecessary for a total head count.
SELECT DISTINCT COUNT(EMPLOYEE_ID) FROM JOBS (Option B): This query is incorrect because DISTINCT applies to the rows returned, not the COUNT function directly. It doesn't address the duplicate EMPLOYEE_ID issue.
SELECT JOB_TYPE, COUNT(DISTINCT EMPLOYEE_ID) FROM JOBS (Option C): While this query correctly uses COUNT(DISTINCT EMPLOYEE_ID) to count unique employees, grouping by JOB_TYPE breaks the count into separate groups, which isn't required for a total head count.
SELECT COUNT(DISTINCT EMPLOYEE_ID) FROM JOBS (Option D): This query correctly counts only unique EMPLOYEE_IDs by using the DISTINCT keyword within the COUNT function, providing an accurate total head count without grouping.
The DA0-002 Data Analysis domain emphasizes 'given a scenario, applying the appropriate descriptive statistical methods using SQL queries,' which includes handling duplicates with functions like COUNT(DISTINCT). Option D is the most direct and accurate method for a total unique head count.
==============
Currently there are no comments in this discussion, be the first to comment!