0

我正在为三个表“进程名称”、“Work_Log1”和“ACn_reviewer”编写一个ms 访问查询。

现在“Work_Log1”表具有“进程名称”和“ACN_REviewer”表的外键。

但是“Work_log1”表在“ACN_Reviewer”表的某些行中有空值。

我提出的工作查询

select w.[activity_id], w.[activity_start_date], w.[reporting month] , 
r.[Reviewer_Name] , p.[process_name]
from [process name] p left join 
([work_log1] w left join [acn_reviewer] r
on w.[ACN Reviwer] = r.[ACN_Reviewer_ID]  )
on w.[process] = p.[process_id] 
 where w.[activity_id] = 54447 

现在我知道 work_log1 表中没有进程 ID 为空。

我问的问题是否有某种方法可以在没有连接的情况下进行上述查询?

像这样的东西,只在 acn_reviewer 上加入

 select w.[activity_id], w.[activity_start_date], w.[reporting month] , 
r.[Reviewer_Name] , p.[process_name]
from [process name] p  ,   [work_log1] w left join [acn_reviewer] r
 on w.[ACN Reviwer] = r.[ACN_Reviewer_ID]   
  where w.[process] = p.[process_id] and 
  w.[activity_id] = 54447 

我希望现在我清楚

那么我可以在 sql 中写这样的东西吗,这会在 ms-access 中引发错误

select w.[activity_id], w.[activity_start_date], w.[reporting month] ,
r.[Reviewer_Name] , p.[process_name] from [process name] p, [work_log1] w 
left join [acn_reviewer] r
on w.[ACN Reviwer] = r.[ACN_Reviewer_ID]  on w.[process] = p.[process_id]
 where w.[activity_id] = 54447 ;

谢谢

普拉久特

4

2 回答 2

1

根据我从上面的属性中收集到的信息:

Process Name (p)
p.[process_name]
p.[process_id]

Work_Log1 (w)
w.[activity_id]
w.[process]
w.[acn reviwer]
w.[activity_start_date]
w.[reporting month]

ACN Reviewer (r)
r.[acn_reviewer_id]
r.[reviewer_name]

又是怎样的Process Name关系ACN Reviewer?如果不是,则无法根据NULL.Work_Log1

于 2012-09-17T19:54:31.957 回答
0

最后一次尝试: 我在想....也许你想将这些结果联合到另一个选择与 work_log1 left join'd to acn_reviewer (不先将 work_log1 与 process 一起加入)以获得 process 为 null 而 acn_reviewer 不是的情况?是的?不...?谁知道。我累了。访问不允许完整的外部连接和东西所以....也许这就是你想要做的,实际上?

        select  pw.[activity_id], 
                pw.[activity_start_date], 
                pw.[reporting month] ,
                r.[Reviewer_Name], 
                pw.[process_name] 

        from    ([work_log1] as w

                join [process name] as p 
                on w.[process] = p.[process_id] ) as pw

                    join [acn_reviewer] as r
                    on pw.[ACN Reviwer] = r.[ACN_Reviewer_ID]  

        where   pw.[activity_id] = 54447 

        -- all records in work_log1 that have a matching row both
                    -- in acn_reviewer and process via the join 

        union 


        select  pw.[activity_id], 
                pw.[activity_start_date], 
                pw.[reporting month] ,
                null as [Reviewer_Name], 
                pw.[process_name] 

        from    ([work_log1] as w

                join [process name] as p 
                on w.[process] = p.[process_id] ) as pw

                    left join [acn_reviewer] as r
                    on pw.[ACN Reviwer] = r.[ACN_Reviewer_ID]  

        where   pw.[activity_id] = 54447 and r.[acn reviewer] is null

        -- all records where work_log1, WITH a row in process, 
                    -- WITHOUT a row in acn_reviewer 

        union

        select  pw.[activity_id], 
                pw.[activity_start_date], 
                pw.[reporting month] ,
                r.[Reviewer_Name] as [Reviewer_Name], 
                null as [process_name] 

        from    ([work_log1] as w

                join [acn_reviewer] as r
                on w.[ACN Reviwer] = r.[ACN_Reviewer_ID] ) as wr

                    left join [process name] as p 
                    on w.[process] = p.[process_id]  

        where   pw.[activity_id] = 54447 and p.[process_id] is null

        -- all records where work_log1, WITHOUT a row in process, 
                    -- WITH a row in acn_reviewer 

        union


        select  pw.[activity_id], 
                pw.[activity_start_date], 
                pw.[reporting month] ,
                null as [Reviewer_Name], 
                null as [process_name] 

        from    ([work_log1] as w

                left outer join [acn_reviewer] as r
                on w.[ACN Reviwer] = r.[ACN_Reviewer_ID]  ) as wr

                    left outer join [process name] as p 
                    on wr.[process] = p.[process_id]

        where   pw.[activity_id] = 54447 and p.[process_id] is null and wr.[ACN_Reviewer_ID] is null

        -- all records in work_log1 that have no matching rows in either process or acn_reviewier
                    --  cuzzz its a left outer join and the where says the joined tables return null-thing

访问很奇怪,如果您将整个内容放入 a 中,可能会或可能不喜欢它,select * from (query with unions) as x where activity_id = 54447但我不确定。我没有测试过这个。但你有希望得到这个想法。希望这就是你想要的。*如果不是 ---> 像 njk 这样的 ERD 提供给我们/您是正确的(b/c 您说他的错误)将非常有帮助,没有它或没有显示您需要的 NULL 的示例结果集我只是无法继续。*

或者...您的第一个查询剥离了连接?

select  w.[activity_id], 
        w.[activity_start_date], 
        w.[reporting month], 
        r.[Reviewer_Name], 
        p.[process_name]

from    work_log1 as w, acn_reviewer as r, process as p 

where   (w.[acn reviewer] = r.acn_reviewer_id or r.acn_reviewer_id is null) and 
        w.process = p.process_id 
于 2012-09-17T20:11:28.273 回答