表名demo
ID date
1 2017-10-07
2 2017-10-07
3 2017-10-07
4 2017-10-08
5 2017-10-09
6 2017-10-09
7 2017-10-09
8 2017-10-09
9 2017-10-09
10 2017-10-09
查询2017-10-07到2017-10-09之间,每天都有多少条数据
select count(*) from demo where date<=2017-10-07 and date>=2017-10-09 group by date
select country(*) from demo where date between 2017-10-07 and 2017-10-09 order by data
select count(*) from demo where date between '2017-01-07' and '2017-10-09'
count()
函数中尽量不要用通配符*,具体到某个字段会更好,是哪个字段无所谓;
当数据量大时,就有效的减少了查询时间