我正在尝试使用完全的外连接来连接两个表,但是我没有得到我期望的结果,因为缺少一行。
我正在尝试在3个不同的列中连接这两个表。
表A:
CallId ASId DateTime CallStatus DurationSeconds
21280070 NULL 17/07/2019 in_queue 1
21280070 2099726 17/07/2019 agent_dialing 3
21280070 2099726 17/07/2019 agent_ringing 3
21280070 2099726 17/07/2019 speaking_agent 95
21280070 NULL 17/07/2019 in_queue 1
21280070 2098692 17/07/2019 agent_dialing 1
21280070 2098692 17/07/2019 agent_ringing 6
21280070 2098692 17/07/2019 speaking_agent 10表B:
B.ASId B.CallId B.CallDetails B.DateTime B.Duration
2099726 21280070 dialing 17:21:41 3
2099726 21280070 ringing 17:21:44 3
2099726 21280070 incoming_call_in_conversation 17:23:19 95
2098692 21280070 dialing 17:23:21 1
2098692 21280070 ringing 17:23:27 6
2098692 21280070 incoming_call_in_conversation 17:23:37 10
2098692 21280070 wrapup 17:23:57 20我想得到这样的东西:
A.CallId A.ASId A.DateTime A.CallStatus A.DurationSeconds B.ASId B.CallId B.CallDetails B.DateTime B.Duration
21280070 NULL 17:21:38 in_queue 1 NULL NULL NULL NULL NULL
21280070 2099726 17:21:41 agent_dialing 3 2099726 21280070 dialing 17:21:41 3
21280070 2099726 17:21:44 agent_ringing 3 2099726 21280070 ringing 17:21:44 3
21280070 2099726 17:23:19 speaking_agent 95 2099726 21280070 incoming_call 17:23:19 95
21280070 NULL 17:23:20 in_queue 1 NULL NULL NULL NULL NULL
21280070 2098692 17:23:21 agent_dialing 1 2098692 21280070 dialing 17:23:21 1
21280070 2098692 17:23:27 agent_ringing 6 2098692 21280070 ringing 17:23:27 6
21280070 2098692 17:23:37 speaking_agent 10 2098692 21280070 incoming_call 17:23:37 10
NULL NULL NULL NULL NULL 2098692 21280070 wrapup 17:23:57 20我尝试了下面的代码:
SELECT *
FROM table a
FULL OUTER JOIN table b
ON a.CallId = b.CallId AND a.ASId = b.ASId AND a.DateTime = b.DateTime
WHERE a.CallId = 21280070
ORDER BY a.DateTime我得到的结果比我预期的少了一行,最后一行是wrapup:
A.CallId A.ASId A.DateTime A.CallStatus A.DurationSeconds B.ASId B.CallId B.CallDetails B.DateTime B.Duration
21280070 NULL 17:21:38 in_queue 1 NULL NULL NULL NULL NULL
21280070 2099726 17:21:41 agent_dialing 3 2099726 21280070 dialing 17:21:41 3
21280070 2099726 17:21:44 agent_ringing 3 2099726 21280070 ringing 17:21:44 3
21280070 2099726 17:23:19 speaking_agent 95 2099726 21280070 incoming_call 17:23:19 95
21280070 NULL 17:23:20 in_queue 1 NULL NULL NULL NULL NULL
21280070 2098692 17:23:21 agent_dialing 1 2098692 21280070 dialing 17:23:21 1
21280070 2098692 17:23:27 agent_ringing 6 2098692 21280070 ringing 17:23:27 6
21280070 2098692 17:23:37 speaking_agent 10 2098692 21280070 incoming_call 17:23:37 10有谁知道为什么会发生这种事吗?我不能理解为什么最后一行没有显示。
在此之前,非常感谢您。
致以亲切的问候!
发布于 2019-07-19 00:10:53
因为a.CallId = 21280070。因为当JOIN不成功时,a.CallId的值将为NULL,而此子句将不为真。
在猜测中,你可能想要其中之一:
WHERE 21280070 IN (a.CallId,b.CallId)
WHERE a.CallId = 21280070
OR b.CallId = 21280070https://stackoverflow.com/questions/57098622
复制相似问题