答案 0 :(得分:1)
您可以通过full join-ing
两个表格并使用coalesce
和case
获得所需的结果,如下所示。
SELECT COALESCE(t1.user1, t2.user1) AS "User",
t1.monday,
CASE
WHEN t2.tuesday = t1.monday THEN NULL
ELSE t2.tuesday
END as Tuesday
FROM table1 t1
FULL JOIN table2 t2
ON t1.user1 = t2.user1
ORDER BY "user";
<强>结果:强>
User monday Tuesday
----------------------
user1 gym run
user1 run
user2 gym run
user3 gym
user4 gym
user5 gym
您可以修改演示 here