我正在运行这个查询,它从一个表中选择几个字段并从其他一些表中返回计数。
我的问题:如果我的计数器字段之一计数为零,它不会返回数字 0,它只是空白 - 这是我想尝试解决的问题。
SELECT mem.member_id, mem.screen_name, mem.firstname, mem.lastname, mem.country_code,
mem.joined, rep.rep as reputation, com.cnt as comments FROM members AS mem
LEFT OUTER JOIN (
SELECT member_id, SUM(awarded_what) as rep
FROM members_reputation
GROUP BY member_id) rep
ON mem.member_id = rep.member_id
LEFT OUTER JOIN (
SELECT member_id, COUNT(comment_id) as cnt
FROM blog_comments
GROUP BY comment_id) com
ON mem.member_id = com.member_id
GROUP BY mem.member_id
ORDER BY mem.joined DESC
我想要的是这样的:
Screen Name | Comments
-----------------|--------------------
marty76 | 0
jonnyBoy12 | 0
adamApple | 12
但是,我得到的是这样的东西!
Screen Name | Comments
-----------------|--------------------
marty76 |
jonnyBoy12 |
adamApple | 12
使用我的服务器端语言,这很容易解决,方法是用零替换空值。但我希望零直接来自 SQL,这样我就可以按计数排序。
任何建议都会很棒。