我有下面显示的表格:
login
date user
2016-11-23 1
2016-11-23 2
2016-11-23 3
2016-11-25 2
2016-11-25 5
2016-11-27 1
我想要从上表中获得以下内容:
date count(*)
2016-11-21 0
2016-11-22 0
2016-11-23 3
2016-11-24 0
2016-11-25 2
2016-11-26 0
2016-11-27 1
然而,由于只有日期 2016-11-23
、2016-11-25
和 2016-11-27
,所以当我进行如下查询时:
select date, count(*)
from login
where date between (current_date()-interval 7 day) and current_date()
group by date
order by date asc
我无法得到我真正想要的结果。这个结果可能来自我的登录
表吗?
COUNT(*)
并不好,它会对没有匹配项的日期返回1。 - sagi