我需要从下表中获取具有相同列值的行,我按照以下方式尝试,但它只给我一行。
select *
from employee e
group by e.empsalary
having count(e.empsalary) > 1
表员工
请建议我。
答案 0 :(得分:8)
您应该可以通过将表连接到自身来实现此目的:
SELECT
a.*
FROM
employee a
JOIN employee b
ON a.empsalary = b.empsalary
AND a.empid != b.empid
答案 1 :(得分:3)
使用内部联接加入您发布的查询。
select A.* from employee A
inner join (
select empsalary
from employee
group by empsalary
having count(*) > 1
) B ON A.empsalary = B.empsalary
答案 2 :(得分:2)
这样的事可能
SELECT * FROM employee a
WHERE EXISTS (
SELECT 1 FROM employee b
WHERE a.empsalary = b.empsalary
AND a.empid <> b.empid
);
答案 3 :(得分:2)
select * from employee where empsalary IN(select empsalary from employee group by empsalary having count(empsalary ) > 1)
试试这个。它可以根据需要提供2行。