繁体   English   中英

Mysql需要从table1中获取一列两次,然后通过table2的两个不同列对它们进行排序

[英]Mysql need to get one column two times from table1 and sort them by two different columns of table2

事情就是这样,我有两个表:

  • table1具有intUsersID, varUsersName

  • table2有列intCouriers, intResponsible

intCouriers (具有一些Couriers的intUsersID)和intResponsible (具有一些负责任的intUsersID)

在我的查询中,我必须看到Couriers和负责人的用户名是这样的:

SELECT 
    table1.varUsersName 'Couriers',
    table1.varUsersName 'Responsible'
FROM
    table1 
LEFT JOIN 
    table2 ON table2.intCouriers = table1.intUsersID

然后,我需要一些如何子查询或加入“ table1.varUsersName'Responsible'”的方法,以同时获得“ Reponsible”人员。 请帮我。

应该是这个

SELECT table1.varUsersName 'Couriers', table2.varUsersName 'Responsible'
FROM table1 
INNER JOIN table3  on table1.intUsersID = table3.intCouriers
INNER JOIN table1  as Table2 on  table2.intUsersID = table3. intResponsible
SELECT Couriers.varUsersName as "Couriers",
       Responsible.varUsersName as "Responsible"
FROM   `table2` t2
   LEFT JOIN table1 Couriers on Couriers.intUsersID = t2.intCouriers
   LEFT JOIN table1 Responsible on Responsible.intUsersID = t2.intResponsible

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM