I am trying to get the date and SUM(total) for last 7 days. I am trying this code and getting date NULL and daily_sale 0.00
SELECT
date,
IFNULL( SUM( total ), 0 ) AS daily_sale
FROM sales
WHERE date BETWEEN NOW()
AND DATE_SUB(NOW(), INTERVAL 7 DAY)
I am note sure how to get the date and daily total sale. I want get results as
date daily_sale
2013-01-29 500.00
2013-01-28 500.00
2013-01-27 500.00
2013-01-26 500.00
...
2013-01-23 500.00
You can try with
interval - 7 day:Not sure why
betweendidn’t work, check this out:SQLFIDDLE DEMO