Skip to content
Advertisement

SQL – get MIN value of row and check this MIN value to be in row at least 2 times

What I’m trying to achieve is this:
1) Get the minimum value of a salary in the table for every department.
2) If this minimum value exists in the table at least two times for every department, then show its department id.

Example:

Result:

Advertisement

Answer

If I followed you correctly, you want departments where more than one employee has the lowest salary.

Here is an approach using window functions, which works by comparing row_number() and rank():

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement