mysql 日期分组(补0)

SELECT
	t1.logintime, COALESCE (t2.count, 0) AS count
FROM
	(
		SELECT@cdate := date_add(@cdate, INTERVAL - 1 DAY) AS logintime
		FROM
			(
				SELECT
					@cdate := date_add('结束日期', INTERVAL + 1 DAY)
				FROM
					任意表(本文使用查询表)
			) tmp1
		WHERE
			@cdate > '开始日期'
	
	) t1
LEFT JOIN (
	SELECT
		FROM_UNIXTIME(TEST_DELIVERY_DATE, "%Y-%m-%d") AS logintime, COUNT(1) AS count
	FROM
		查询表
	WHERE
   TEST_DELIVERY_DATE>='2023-02-11'
  and  TEST_DELIVERY_DATE<='2023-03-11'
	GROUP BY
		FROM_UNIXTIME(TEST_DELIVERY_DATE, "%Y-%m-%d")
) t2 
ON t1.logintime = t2.logintime

你可能感兴趣的:(mysql,数据库,sql)