Sql 返回不同的匹配行和非匹配行(外部联接?)

Sql 返回不同的匹配行和非匹配行(外部联接?),sql,oracle,Sql,Oracle,我知道我过去做过,现在想不出解决办法。。。我知道这是一种完全的外部连接 我有三张桌子: ACTIVITIES id name ---+------------- 1 | Basketball 2 | Chess Club ENROLLMENT id activity_id person_id ---+-------------+----------- 1 | 1 | 1

我知道我过去做过,现在想不出解决办法。。。我知道这是一种完全的外部连接

我有三张桌子:

ACTIVITIES       
id   name        
---+-------------
1  |  Basketball 
2  |  Chess Club 

ENROLLMENT                   
id   activity_id   person_id 
---+-------------+-----------
1  | 1           | 1         
2  | 1           | 2         
3  | 2           | 1         

ATTENDANCE
id   date         person_id   activity_id
---+-------------+----------+---------------
1  | 2017-01-01  | 1        | 1
2  | 2017-01-01  | 2        | 1
3  | 2017-01-02  | 1        | 1
我试图通过
个人id
获取出席人数,即使该id在某个日期不存在:

date          person_id
------------+---------------
2017-01-01  | 1
2017-01-02  | null
这里有一些我认为我需要的东西

select date, attendance.person_id
from enrollment
**SOME SORT OF JOIN** attendance on enrollment.person_id = attendance.person_id
where person_id = 1
但我能得到的回报是:

date          person_id
------------+---------------
2017-01-01  | 1
2017-01-01  | 1

…其中行数正确,但值错误。

这似乎会产生您想要的结果:

select date,
       max(case when person_id = 1 then person_id end) as person_id
from attendance a
group by date
order by date;

@yılmaz,因为它将与注册连接,其中存在
个人id
,并且通过
活动id
我的psuedo查询并不完全合理