我有三個表:頁,附件,頁附件SQL查詢,計數爲0計數
我有這樣的數據:
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的一部分?
正如David B.提到這個查詢不會運行。將組更改爲'group by page.name' – edosoft 2009-01-21 13:04:07