Wednesday, 12 March 2025

To find duplicate salaries within each department, you can modify the query as follows:

 SELECT Salary, Department, COUNT(*) AS DuplicateCount

FROM Employees

GROUP BY Salary, Department

HAVING COUNT(*) > 1;

Explanation:

  • GROUP BY Salary, Department ensures that duplicates are checked within each department.
  • COUNT(*) counts occurrences of each (Salary, Department) combination.
  • HAVING COUNT(*) > 1 filters out unique salaries, showing only duplicates.

Example:

Given Employees Table:

EmployeeIDNameSalaryDepartment
1John5000IT
2Alice6000HR
3Mark5000IT
4David7000Sales
5Steve6000HR
6Bob5000HR

Query Output:

SalaryDepartmentDuplicateCount
5000IT2
6000HR2

This means that:

  • Salary 5000 appears twice in the IT department.
  • Salary 6000 appears twice in the HR department.

No comments:

Post a Comment

Car pooling app

 I'll create a car pooling app with real-time vehicle tracking, pickup/drop time estimates, and a list of onboard users. Since we don...