Click here to Skip to main content
15,068,988 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
query to sum the salaries of employees having same name and the result set should show the list of employee names along with their salary

What I have tried:

SELECT Employee_name,
FROM Employee_data
GROUP BY Employee_name,
HAVING COUNT (*) > 1;
SELECT Employee_name SUM(Employee_salary)
FROM Employee_data
GROUP BY Employee_name;
Posted
Updated 28-Aug-21 22:15pm

1 solution

If I understand the requirement correctly, you already have all the elements, just combine the two queries. Something like
SQL
SELECT Employee_name, SUM(Employee_salary), COUNT(*)
FROM Employee_data
GROUP BY Employee_name,
HAVING COUNT (*) > 1;
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900