How can I modify my query to return 0 if count(*) is NULL?
select monthname(timestamp), year(timestamp), count(*)
from largehits
where largeID = someid
and (month(timestamp)<=somemonth
and month(timestamp)>=somemonth
and year(timestamp)<=someyear
and year(timestamp)>=someyear )
group by month(timestamp),开发者_开发知识库 year(timestamp)
order by timestamp asc
Thanks!
BoltClock makes a good point in the comments that COUNT
can never be NULL
.
Generally you would just use COALESCE(expression,0)
for this type of problem though.
Edit: Following clarification in the comments you would need to use an outer join
on a numbers table to get the effect that you want.
精彩评论