Senior
SQL task 2: count and display surnames by groups (GROUP BY, COUNT, HAVING).
sobes.tech AI
Answer from AI
To count and display surnames that occur more than once (i.e., duplicate surnames), you can use the following SQL query:
SELECT last_name, COUNT(*) as count
FROM Employee
GROUP BY last_name
HAVING COUNT(*) > 1;
Here:
GROUP BY last_namegroups records by surname.COUNT(*)counts the number of employees with each surname.HAVING COUNT(*) > 1filters groups where the surname appears more than once.
As a result, you will get a list of surnames and the number of employees with those surnames that are repeated.