[英]Grouping rows from a single day into a count - MYSQL
I've been trying to work through this problem for a bit, and clearly I'm missing something (probably something obvious). 我一直在尝试解决这个问题,但显然我遗漏了一些东西(可能很明显)。
I'm trying to group rows from a single day into a count. 我正在尝试将一天中的行分组为一个计数。 So the output should look like this: 因此输出应如下所示:
Date Count
2009-09-12 2
2009-09-13 5
2010-01-09 4
...and so on. ...等等。
My current SQL looks like this: 我当前的SQL看起来像这样:
SELECT `date`, COUNT(*) FROM `sales_flat_table` GROUP BY `date`;
And outputs data that looks like this: 并输出如下所示的数据:
Date Count
2009-09-12 1
2009-09-12 1
2009-09-13 1
2009-09-13 1
2009-09-13 1
2009-09-13 1
2009-09-13 1
...and so on. ...等等。
What am I missing? 我想念什么? Thanks! 谢谢!
My best guess is that date
is really a datetime
and it has a time component. 我最好的猜测是date
实际上是一个datetime
时间,它具有时间成分。 To get just the date, use the date()
function: 要仅获取日期,请使用date()
函数:
SELECT date(`date`) as `date`, COUNT(*)
FROM `sales_flat_table`
GROUP BY date(`date`);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.