【问题标题】:Multiple joins on the same table同一张表上的多个连接
【发布时间】:2015-07-24 02:10:39
【问题描述】:

我有以下表格:

Technician
Tech_ID,First_Name,Last_Name

 RT_QUEUE_Delta
 Tech_ID, RT_Complete` (references a `Tech_ID` in `Technician`).

我需要从RT_Queue_Delta 中的一行获取数据,其中RT_Completed = ?? 但在我的输出中我需要有与Tech_idRT_Completed 相关的First_NameLast_name。

我可以匹配一个,但我不知道如何匹配两个。我试过了:

select RTTech.First_Name as RT_First_Name,
       RTTech.Last_Name as RT_Last_Name
from Technician as RTTech 
         Join RT_Queue_Delta as RT 
         on RT.RT_Completed = RTTech.Tech_ID

【问题讨论】:

    标签: mysql sql oracle sqlite join


    【解决方案1】:

    您可以多次加入Technician 表:

    select d.tech_id, t.first_name, t.last_name, 
           d.rt_completed as completed_id, 
           t2.first_name as completed_first_name, 
           t2.last_name as completed_last_name
    from RT_QUEUE_Delta d
        join Technician t on d.tech_id = t.tech_id
        join Technician t2 on d.RT_Completed = t2.tech_id
    

    【讨论】:

    • 这正是我所需要的,非常感谢!
    猜你喜欢
    • 2015-05-18
    • 1970-01-01
    • 2016-03-07
    • 2011-10-18
    • 1970-01-01
    • 2013-05-23
    • 2021-01-09
    • 1970-01-01
    相关资源
    最近更新 更多