0
departments: id, title
comments: id, year_code
department_comments: comment_id, department_id
我想列出每個部門的標題,用的有多少意見具有計數。
東西沿着
select
d.title, count(c.id) as total_comments
from
departments d, comments c
left join
department_comments dc on c.id = dc.comment_id
where
c.year_code = 1011
上述查詢的行不行,但應該給你什麼,我試圖完成一個想法。
我要顯示給用戶的是部門標題和它旁邊,像下面的註釋總#:
d.title (count(c.id))
---------------------
Maintenance (10)
Finance (5)
Security (13)