我有兩張表,其中包含一些等于欄位和一個不同的欄位:
表一 - Ingresaron
DepartmentId Fecha_Lunes Entraron
------------ ----------- -----------
26 2022-08-01 1
26 2022-08-15 2
26 2022-08-22 3
26 2022-08-08 3
表二 - Salieron
DepartmentId Fecha_Lunes Salieron
------------ ----------- -----------
26 2022-08-15 3
26 2022-08-22 4
26 2022-08-08 2
26 2022-08-29 1
我正在尋找回傳這樣一個結果集的查詢:
DepartmentId Fecha_Lunes Salieron Entraron
------------ ----------- ---------- -----------
26 2022-08-01 null 1
26 2022-08-08 2 3
26 2022-08-15 3 1
26 2022-08-22 4 2
26 2022-08-29 1 null
但是無論JOIN,LEFT JOIN,RIGHT JOIN,CROSS JOIN的什么組合我都無法解決,請你幫幫我嗎?
uj5u.com熱心網友回復:
完全加入會做:
select coalesce(ing.DepartmentId, s.DepartmentId) as DepartmentId,
coalesce(ing.Fecha_lunes, s.Fecha_lunes) as Fecha_lunes,
s.Saileron,
ing.Entraron
from ingresaron ing
full join saileron s on ing.departmentId = s.DepartmentId and ing.Fecha_lunes = s.Fecha_lunes;
編輯
2022-08-29沒有問題,不排除。查看
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/504033.html
