I been trying to make this one work, but can't find a solution.
I want to grab the SUM
of a row for a given date, and if there is no entry for that date, return a 0
. I tried using IFNULL()
but can't make it work.
My query grabs the data for the last 15 dates and SUMS
the content for each date. Here is the query
SELECT date(left(date_column, 10)) as dd, ROUND(SUM(sum_total)/1000)
as cnt FROM order_table WHERE date(left(date_column, 10)) >= DATE_ADD(CURDATE(), INTERVAL -14 DAY)
GROUP BY date(left(date_column, 10)) ORDER BY dd ASC
I tried
SELECT date(left(date_column, 10)) as dd, IFNULL ( ROUND(SUM(sum_total)/1000) ,'0')
FROM order_table WHERE date(left(date_column, 10)) >= DATE_ADD(CURDATE(), INTERVAL -14 DAY)
GROUP BY date(left(date_column, 10)) ORDER BY dd ASC
My problem occurs when there is no data for a given date and therefore the date is skipped.
Any tip in the right direction will be appreciated