如果我有桌子...

  ID     Name   Manager
  0      Joe    Sue
  1      Jake   Tom
  0      Joe    Tom
  2      Larry  Red
  2      Larry  Paul
  1      Jake   Paul

我希望输出是...
 ID   Name   Manager1    Manager2
 0    Joe    Sue         Tom
 1    Jake   Tom         Paul
 2    Larry  Red         Paul

谢谢...

最佳答案

是的,如果您的表被称为“经理”:

SELECT Mgr1.ID,Mgr1.Name,Mgr1.Manager,Mgr2.Manager
FROM Managers AS Mgr1
LEFT JOIN Managers AS Mgr2
ON Mgr1.ID=Mgr2.ID

关于sql - 我应该使用自加入,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3863830/

10-11 08:04