直接上代码吧!!
SELECT
dates,
#判断当前count是否有值没有为0
IFNULL( count, 0 ) count
FROM
(
SELECT
@s := @s + 1 AS indexs,
DATE_FORMAT( DATE( DATE_SUB( CURRENT_DATE, INTERVAL @s DAY ) ), '%Y-%m-%d' ) AS dates
FROM
mysql.help_topic,
( SELECT @s := 0 ) temp #不想包含当天,@s:=0 包含当天-1 跳过一天 1
WHERE
@s < 45
ORDER BY
dates
) date_table
LEFT JOIN (select DATE_FORMAT( DATE(time), '%Y-%m-%d' ) as time , count(1)as count from merchant_account GROUP BY time)
mac ON date_table.dates = mac.time
GROUP BY
date_table.dates
ORDER BY
date_table.dates DESC