当我在视图中选择数据时, 在大多数情况下,我将获得数据:
Referred Job_Status Jobs
OPS DISPATCHED 9
OPS NOT_DISPATCHED 3
但是有时候数据不存在,我只能得到这个:
Referred Job_Status Jobs
OPS DISPATCHED 9
当它不存在时,我仍然想将其显示为零:
Referred Job_Status Jobs
OPS DISPATCHED 9
OPS NOT_DISPATCHED 0
对不起,我有一个星期五早上,我无法直截了当。
答案 0 :(得分:2)
您可以尝试以下操作:
with main as (
select 'OPS' Referred ,'DISPATCHED' Job_Status FROM DUAL
UNION
select 'OPS' Referred ,'NOT_DISPATCHED ' Job_Status FROM DUAL
)
SELECT
MAIN.Referred ,MAIN.Job_Status , NVL(SUB.JOBS,0) JOBS
FROM MAIN LEFT OUTER JOIN YOUR_VIEW SUB ON MAIN.REFERRED=SUB .REFERRED
AND MAIN.Job_Status =SUB.Job_Status ;