Senior
SQL task 4: List the first and last names of employees who completed more than two tasks.
sobes.tech AI
Answer from AI
To display the first and last names of employees who have completed more than two tasks, you can use the following SQL query. Suppose there are tables:
employeeswith fieldsemployee_id,first_name,last_nametaskswith fieldstask_id,employee_id
Query:
SELECT e.first_name, e.last_name
FROM employees e
JOIN tasks t ON e.employee_id = t.employee_id
GROUP BY e.employee_id, e.first_name, e.last_name
HAVING COUNT(t.task_id) > 2;
Explanation:
- Join employees with their tasks on
employee_id. - Group by employee.
- Use
HAVINGto filter those with more than two tasks.
This is a standard way to get a list of employees with more than two completed tasks.