我有一个查询来检索四月份的数据。
SELECT DATE(a.`senddate`) AS 'Date',SUM(a.`msglength`) AS 'total' FROM mytable a WHERE userid='248283' and senddate > '20170401000000' and senddate < '20170501000000' GROUP BY 1;
由于桌子的大小,需要花费很多时间。无法更改结构,也无法添加任何索引。
如何编写存储过程以便我可以遍历每一天。有点像...
SELECT DATE(a.`senddate`) AS 'Date',SUM(a.`msglength`) AS 'total' FROM mytable a WHERE userid='248283' and senddate > '20170401000000' and senddate < '20170402000000' GROUP BY 1;
SELECT DATE(a.`senddate`) AS 'Date',SUM(a.`msglength`) AS 'total' FROM mytable a WHERE userid='248283' and senddate > '20170402000000' and senddate < '20170403000000' GROUP BY 1;
直到最后一天。