我试图弄清楚如何将这两个SQL语句合并为一个。我希望最终结果在一个查询中...如果可能的话。
SELECT WHM_ilvl AS BestWHM_ilvl, username AS BestWHM_Name FROM roster ORDER BY WHM_ilvl DESC
SELECT BLM_ilvl AS BestBLM_ilvl, username AS BestBLM_Name FROM roster ORDER BY BLM_ilvl DESC
结果如下:
BestWHM_ilvl | BestWHM_ilvl | BestBLM_ilvl | BestBLM_ilvl
107 | User1 | 121 | user2
102 | User11 | 109 | user3
80 | User3 | 101 | user52
79 | User7 | 99 | user3
78 | User4 | 80 | user1
我尝试用()将它们分开并将它们包括在内,好像它们是单列但它不起作用。我尝试寻找我想要的相同类型的查询但从未找到任何东西。
如果可以的话,我不介意提到正确的知识。
我在PHP和MySQL中使用它。
的问候,
答案 0 :(得分:0)
SELECT
r1.WHM_ilvl AS BestWHM_ilvl
, r1.username AS BestWHM_Name
, r2.BLM_ilvl AS BestBLM_ilvl
, r2.username AS BestBLM_Name
FROM roster r1
JOIN roster r2 ON r1.id = r2.id
ORDER BY r1.WHM_ilvl, r2.BLM_ilvl
DESC
这是查询问题的最简单形式的查询。似乎可能还有更多,如果这样更新,我会尝试回到这个。
编辑糟糕。纠正了我之前应该抓住的一些事情。