我有三张表:页、附件、页附件
我有这样的数据:
page
ID NAME
1 first page
2 second page
3 third page
4 fourth page
attachment
ID NAME
1 foo.word
2 test.xsl
3 mm.ppt
page-attachment
ID PAGE-ID ATTACHMENT-ID
1 2 1
2 2 2
3 3 3
当每页附件数为0时,我也想得到该数。我尝试过:
select page.name, count(page-attachment.id) as attachmentsnumber
from page
inner join page-attachment on page.id=page-id
group by page.id
我得到的输出是:
NAME ATTACHMENTSNUMBER
second page 2
third page 1
我想得到这个输出:
NAME ATTACHMENTSNUMBER
first page 0
second page 2
third page 1
fourth page 0
如何获取0部分?