Mysql统计结果为零值
在mysql中,我得到了表“分数”,如下所示
Id Date Name score
1 2011-08-24 00:00:00 sharique 10
2 2011-08-24 00:00:00 joe 11
3 2011-08-24 00:00:00 vijay 5
4 2011-08-25 00:00:00 sharique 0
5 2011-08-25 00:00:00 joe 11
现在当我运行查询时,
SELECT date,count(id) as count FROM scores where `name` = 'vijay' group by `date`;
我得到的结果是
date count
2011-08-24 00:00:00, 1
而不是
date count
2011-08-24 00:00:00, 1
2011-08-25 00:00:00, 0
如何显示零计数的结果,请问?
In mysql, I got table "scores" as follow
Id Date Name score
1 2011-08-24 00:00:00 sharique 10
2 2011-08-24 00:00:00 joe 11
3 2011-08-24 00:00:00 vijay 5
4 2011-08-25 00:00:00 sharique 0
5 2011-08-25 00:00:00 joe 11
Now when I am running query
SELECT date,count(id) as count FROM scores where `name` = 'vijay' group by `date`;
I am getting result as
date count
2011-08-24 00:00:00, 1
instead of
date count
2011-08-24 00:00:00, 1
2011-08-25 00:00:00, 0
how can i display result with zero count, please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一种简单的方法:
这保证了表中每个不同日期的每个人都有一个日期
Here's one simple way:
This guarantees a date for everybody for every distinct date in the table
这是您计算与 where 条件匹配的行数时的预期结果。
它只选择一条记录,因此计数结果为 1。
如果您想对所有行进行计数,请不要使用
Where Clause
来限制数据,例如:-同样,以下查询将返回 3作为计数..
It is The Expected Result as You Are Counting the number of rows that matches your where condition.
It selects only one record hence the result of count is 1.
If you want to count all the rows use don't restrict the data by using
Where Clause
e.g:-Like wise the following query will return 3 as count..