【发布时间】:2019-01-04 22:06:48
【问题描述】:
我将通过 regNo 列加入两个表。我想添加 regNo 匹配的 Table1.points 和 Table2.points 点,以防万一它不匹配我还希望它包含在列表中的点中,如下图所示
我已经阅读了现有的问题,但没有找到解决方案,例如How can I sum columns across multiple tables in MySQL?
(
SELECT `Ex`.regNo,(`In`.`points`+`Ex`.`points`) AS 'Points'
FROM Table1`In`
LEFT JOIN Table2`Ex` ON `In`.`regNo` = `In`.`regNo`
)
UNION
(
SELECT`Ex`.regNo,(`In`.`points`+`Ex`.`points`) AS 'Points'
FROM Table1`In`
RIGHT JOIN Table2`Ex` ON `In`.`regNo` = `In`.`regNo`
);
我希望它提供按照唯一 (DISTINCT) regNo 排列的列表
【问题讨论】:
标签: mysql join outer-join