不要再用dataformat统计每天的日期的count了
最近在优化报表统计图的查询速度
要查询每天某一项的count数量,由于需要group by 走索引
但是dataformat属于mysql函数不能走索引
所有我看了MySQL的其他速度比dataformat快的函数
第一个是
1.字符串截取:substring,从第一个字段截取到第十个字符串,然后group by
SELECT substring(time, 1, 10),count(distinct customers_ip) as days_count
FROM `table` group by
substring(customers_ip_date, 1, 10)
2.使用cast函数,进行group by
SELECT cast(my_time as date) as date,count(*) FROM `table`
group by cast(my_time as date)
经过实验substring函数和cast函数都比datafomat快数倍
cast函数最快 但是要注意MySQL使用函数都是无法走索引的