Suppose we have 3 employees in each department.we have total 3 departments . Below is the sample source table
Emp deptno salary A 10 1000 B 10
Solution using Correlated Subquery:
Correlated Subquery
SELECT * FROM emp e1 WHERE 2 = (SELECT COUNT(DISTINCT sal) FROM emp e2 WHERE e1.sal <= e2.sal AND e1.deptno = e2.deptno );