我正在处理一个视图(最初不是由我自己创建的),我正在尝试做的是返回请求(表别名req),没有分配给他们的时间(表别名te),我有点难以获得任何类型的外连接在以下sql上返回:
SELECT
te.tc_date_yyyy_ww,
te.tc_date_yyyy_mm,
te.tc_date_yyyy,
te.dc_date,
te.nc_request_id_fk,
te.nc_subrequest_id_fk,
te.tc_clock,
te.nc_hours,
te.nc_amount,
te.nc_discipline_id_fk,
te.tc_discipline_desc,
req.tc_request_name,
req.mc_project_cost,
req.nt_fetr_project,
req.nc_bus_unit_id_fk,
req.nc_location_id_fk,
req.nc_cemt_status_id_fk,
coord.tc_user_fname || ' ' || coord.tc_user_lname AS projectcoodname,
assoc.tc_fname || ' ' || assoc.tc_lname AS empname,
assoc_disc.tc_long_desc AS user_discipline,
sr.tc_name AS child_project,
sr.tc_cost_center_or_wbs,
sr.tc_cost_center_nbr,
sr.tc_cost_center_desc,
sr.tc_profit_center_desc,
sr.tc_profit_center_nbr,
sr.tc_wbs_nbr,
sr.tc_wbs_desc,
sr.nc_child_type_id_fk,
sre.nc_estimate,
stat_li.tc_med_desc AS req_status,
NVL(PP.NC_PRIORITY,0) AS PRIORITY
FROM te07fear.tbye10_time_entry te,
te07fear.tbxg100_requests req,
(SELECT *
FROM te07fear.tbye05_form_users
WHERE tc_role_id_fk = 'project_coordinator') coord,
te07fear.tbye07_subrequest sr,
te07fear.tbye08_subrequest_est sre,
te07fear.tbye02_list_items stat_li,
te07fear.tbye04_associates assoc,
te07fear.tbxg95_dropdowns assoc_disc,
TE07FEAR.TBYF43_PROJECT_PRIORITY PP
WHERE
te.tc_clock = assoc.tc_clock
AND
te.nc_subrequest_id_fk = sr.nc_subrequest_id(+)
AND
te.nc_subrequest_id_fk = sre.nc_subrequest_id_fk(+)
AND
te.tc_clock = sre.tc_clock(+)
AND
te.nc_request_id_fk = req.nc_request_id
AND
te.nc_request_id_fk = coord.nc_form_id_fk
AND
assoc.nc_discipline_id_fk = assoc_disc.nc_key_id
AND
req.nc_cemt_status_id_fk = stat_li.nc_value_id
AND
TE.NC_REQUEST_ID_FK = PP.NC_REQUEST_ID_FK
AND
TE.NC_SUBREQUEST_ID_FK = PP.NC_SUB_REQUEST_ID_FK
AND
TE.TC_DATE_YYYY_WW = PP.TC_DATE_YYYY_WW
AND
TE.TC_CLOCK = PP.TC_CLOCK_NUMBER
任何帮助或想法都会非常感激。我假设左外连接应该让我能够做到这一点。
由于 JC
答案 0 :(得分:0)
据我了解,你实际上需要NOT EXISTS
子句,而不是外连接。
这是一个简化的代码段,向您展示我的意思(跳过大部分查询,但您已经明白了这一点):
SELECT req.tc_request_name,
req.mc_project_cost,
req.nt_fetr_project,
req.nc_bus_unit_id_fk,
req.nc_location_id_fk,
req.nc_cemt_status_id_fk
FROM te07fear.tbxg100_requests req
WHERE NOT EXISTS (select 1
from te07fear.tbye10_time_entry te
where te.nc_request_id_fk = req.nc_request_id)
;
如果情况确实如此,请告知我们是否符合此目的。
干杯