如何获取具有多个员工编号的员工的重复姓名

发布于 2024-12-11 14:42:34 字数 686 浏览 0 评论 0原文

我使用的是Oracle 10g。

如果我有以下重复行(具有两个员工编号的同一员工):

Employee_No      Employee_Name      ID_NO
----------------------------------------------
0002345          John Debb          100345642
0030988          John Debb          100345642
----------------------------------------------

我想得到的结果为:

Employee_No_1      Employee_No_2     Employee Name    ID_NO
----------------------------------------------------------------
0002345            0030988           John Debb        100345642
----------------------------------------------------------------

是否可以在 SQL 中完成?或者它需要 PL/SQL?查询是什么?

I'm using Oracle 10g.

If i have the following duplicate rows (Same Employee with two Employee numbers):

Employee_No      Employee_Name      ID_NO
----------------------------------------------
0002345          John Debb          100345642
0030988          John Debb          100345642
----------------------------------------------

i want to get the result as:

Employee_No_1      Employee_No_2     Employee Name    ID_NO
----------------------------------------------------------------
0002345            0030988           John Debb        100345642
----------------------------------------------------------------

Is it possible to be done in SQL? or it needs PL/SQL? and what would the query be?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

飘落散花 2024-12-18 14:42:34
SELECT MIN(Employee_no), MAX(employee_no), Employee_name, id_no
FROM Employee
GROUP BY Employee_name, id_no
HAVING MIN(employee_no) <> MAX(employee_no)

我不使用 Oracle,但我认为这是非常通用的语法,应该可以工作。

SELECT MIN(Employee_no), MAX(employee_no), Employee_name, id_no
FROM Employee
GROUP BY Employee_name, id_no
HAVING MIN(employee_no) <> MAX(employee_no)

I don't do Oracle, but I think this is pretty generic syntax that should work.

倾城花音 2024-12-18 14:42:34

不完全符合所要求的格式,但这将处理可能有超过 2 个重复项的情况。

SELECT e.Employee_No, e.Employee_Name, e.ID_NO
    FROM (SELECT Employee_Name, ID_NO
              FROM Employee
              GROUP BY Employee_Name, ID_NO
              HAVING COUNT(*) > 1) q
        INNER JOIN Employee e
            ON q.Employee_Name = e.Employee_Name
                AND q.ID_NO = e.ID_NO
    ORDER BY e.Employee_Name, e.ID_NO, e.Employee_No

Not quite in the format requested, but this will handle the case where there could be more than just 2 duplicates.

SELECT e.Employee_No, e.Employee_Name, e.ID_NO
    FROM (SELECT Employee_Name, ID_NO
              FROM Employee
              GROUP BY Employee_Name, ID_NO
              HAVING COUNT(*) > 1) q
        INNER JOIN Employee e
            ON q.Employee_Name = e.Employee_Name
                AND q.ID_NO = e.ID_NO
    ORDER BY e.Employee_Name, e.ID_NO, e.Employee_No
一曲琵琶半遮面シ 2024-12-18 14:42:34

查询如下,

select e1.employee_no, e2.employee_no, e1.employee_name, e1.id_no
from employee e1
join employee e2
    on e1.id_no = e2.id_no
where e1.employee_no < e2.employee_no

Query is as below,

select e1.employee_no, e2.employee_no, e1.employee_name, e1.id_no
from employee e1
join employee e2
    on e1.id_no = e2.id_no
where e1.employee_no < e2.employee_no
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文