I have such script to query userCount from start of one day 'xxxx-xx-xx 00:00:00'
, to end of this day 'xxxx-xx-xx 23:59:59'
.
USE db;
SELECT user
FROM db.user AS user
WHERE
user.payTime BETWEEN '2017-07-12 00:00:00' AND '2017-07-12 23:59:59'
GROUP BY user.username
So now how can I query the user's payTime within the day from 2017-06-01
to 2017-07-12
?
The first thing came out of my mind is declared a date range:
SET CURRDATE = '2017-06-01';
SET ENDDATE = '2017-07-12';
and put the script into a loop like:
WHILE CURRDATE < ENDDATE DO
USE db;
.......
WHERE
user.payTime BETWEEN 'CURRDATE 00:00:00' AND 'CURRDATE 23:59:59'
.......
SET CURRDATE = DATE_ADD(CURRDATE, INTERVAL 1 DAY)
END WHILE;