I am trying to get COUNT of all user attempts in the list of the current week (last 7 days)
This query works, but does not return 0 if the day does not exist:
SELECT COUNT(*) AS attempt_count, DATE_FORMAT(attempt_date,'%Y/%m/%d') AS attempt_date FROM users_attempts WHERE DATE_SUB(attempt_date, INTERVAL 1 DAY) > DATE_SUB(DATE(NOW()), INTERVAL 1 WEEK) GROUP BY DAY(attempt_date) DESC;
This query returns COUNT of all attempts of the last current week per day, I got this (I have only 1 record):
attempt_count | attempt_date 1 2014/06/19
I want this result:
attempt_count | attempt_date 1 2014/06/19 0 2014/06/18 0 2014/06/17 0 2014/06/16 0 2014/06/15 0 2014/06/14 0 2014/06/13
Thank you very much
DEMO : http://sqlfiddle.com/#!2/b58bb/1/0
date sql mysql count
Jonathan Edgardo Jun 19 '14 at 7:40 2014-06-19 07:40
source share