我正在使用以下查询,如果这有点混乱,我深表歉意,这是我能获得给我想要的结果的唯一方法:)但是在最左侧的“ PO”列中,所有这些都说完了,就可以了是(null)的单个实例,请参见示例输出。当我确定数值应该具有值时,这导致数值显示为(空)。
我没有成功使用NVL,NVL2,COALESCE函数。
select query2.PO, query2.Work_Group, query2.PO_QTY_TO_Move, query8.Active_Pick_Faces AS Active_Pick_Faces, query4.C0R_Qty_To_Move AS Move_C0R, query6.NA_Qty_To_Move AS Move_NA
from((select PO, Work_Group, SUM(qty_to_move) AS PO_Qty_To_Move
from(select order_header.purchase_order AS PO,order_header.work_group AS Work_Group, move_task.task_id, move_task.qty_to_move AS qty_to_move
from order_header
left join move_task
on order_header.order_id = move_task.task_id
where move_task.site_id = 'USCOL1' and move_task.client_id = 'SDRY-US' and move_task.status != 'Consol' )query1
group by PO, Work_Group)query2
left join
(select PO, Work_Group, SUM(qty_to_move) AS C0R_Qty_To_Move
from(select order_header.purchase_order AS PO,order_header.work_group AS Work_Group, move_task.task_id, move_task.from_loc_id, move_task.qty_to_move AS qty_to_move
from order_header
left join move_task
on order_header.order_id = move_task.task_id
left join location
on move_task.from_loc_id = location.location_id
where move_task.site_id = 'USCOL1' and move_task.client_id = 'SDRY-US' and location.work_zone = 'C0-R' and move_task.status != 'Consol' or order_header.purchase_order is null)query3
group by PO, Work_Group)query4
on query2.PO = query4.PO
left join
(select PO, Work_Group, SUM(qty_to_move) AS NA_Qty_To_Move
from(select order_header.purchase_order AS PO,order_header.work_group AS Work_Group, move_task.task_id, move_task.qty_to_move AS qty_to_move
from order_header
left join move_task
on order_header.order_id = move_task.task_id
where move_task.site_id = 'USCOL1' and move_task.client_id = 'SDRY-US' and move_task.from_loc_id like 'NA%' and move_task.from_loc_id not like '%PAL%' and move_task.status != 'Consol' )query5
group by PO, Work_Group) query6
on query2.PO = query6.PO
left join
(select PO, Work_Group, SUM(qty_to_move) AS Active_Pick_Faces
from(select order_header.purchase_order AS PO,order_header.work_group AS Work_Group, move_task.task_id, move_task.qty_to_move AS qty_to_move
from order_header
left join move_task
on order_header.order_id = move_task.task_id
left join location
on move_task.from_loc_id = location.location_id
where move_task.site_id = 'USCOL1' and move_task.client_id = 'SDRY-US' and location.work_zone in ('C0S','C0S2','LAUNCH','C0-RPALLET', 'TRANSIT')and move_task.status != 'Consol' or move_task.from_loc_id like '%PAL%')query7
group by PO, Work_Group) query8
on query2.PO = query8.PO)
答案 0 :(得分:1)
您使用的连接条件如下:
on query2.PO = query8.PO
但是null永远不会等于(或不等于)其他任何东西,因此,如果PO
为null,则不能使用相等检查;您需要使用is null
。您想同时检查两者时:
on query2.PO = query8.PO
or (query2.PO is null and query8.PO is null)