我有三个表:page、attachment、page-attachment。
我的数据如下:
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部分?