如果SQL或Access中的逻辑查询

Eny*_*ius 3 sql database ms-access

问候,SO人.

我正在开发一个让我使用Access数据库的项目.这是设置:

我有三张桌子:

Tab1 with employee names, ID#s, Manager names and Manager ID#s.
Tab2 with chat info, employee ID#s and employee names.
Tab3 with Manager ID#s, Manager names and team names.
Run Code Online (Sandbox Code Playgroud)

我目前有一个选择以下内容的查询:

tab2.[employee name], tab2.[employee id], tab3.[chat info], tab1.[manager id], tab1.[manager id], tab3.[team name]
where
tab2.[employee id] = tab1.[employee id] and tab2.[manager id] = tab3.[manager id];
Run Code Online (Sandbox Code Playgroud)

我想要完成的是:如果ID在行的某个地方不匹配,我想有办法在"团队"字段中放置"未知".有任何想法吗?

提前致谢!

Joe*_*lli 5

也许是这样的:

select tab2.[employee name], 
       tab2.[employee id], 
       tab3.[chat info], 
       tab1.[manager id], 
       Nz(tab3.[team name], 'Unknown') as [team name]
    from (tab2
        left join tab1
            on tab2.[employee id] = tab1.[employee id])
        left join tab3
            on tab2.[manager id] = tab3.[manager id]
Run Code Online (Sandbox Code Playgroud)