我有以下声明:
select count(*), FirstAdded from db.table where date(FirstAdded) between '2013-07-01' and '2013-07-10' group by Firstadded order by count(*)
当我执行它时,它会在每次向表中添加一行时返回数据。
1 | 2013-07-03 15:22:14
1 | 2013-07-03 15:23:14
1 | 2013-07-03 15:22:42
1 | 2013-07-03 15:45:29
我想将这一点贬低为每天添加的行数(没有m:s时间,仅为整天)。 e.g。
345 | 2013-07-03
7482 | 2013-07-04
1237 | 2013-07-05
这可能吗?
答案 0 :(得分:3)
这是group by
查询:
select date(FirstAdded), count(*)
from db.table
group by date(FirstAdded);
函数date()
将日期时间值转换为日期值,这似乎是您想要的。
您的完整查询将是:
select count(*), date(FirstAdded)
from db.table
where date(FirstAdded) between '2013-07-01' and '2013-07-10'
group by date(Firstadded)
order by count(*)