传入YYYY-MM-01,查询这个月中每一天的数据量,没有数据的天数用0表示
WITH RECURSIVE DateRange AS (
SELECT :startDate AS Date
UNION ALL
SELECT DATE_ADD(Date, INTERVAL 1 DAY) FROM DateRange
WHERE Date < LAST_DAY(:startDate)
)
SELECT
dr.Date,
COALESCE(COUNT(yt.createTime), 0) AS DataCount
FROM
DateRange dr
LEFT JOIN
t_student yt ON DATE(yt.createTime) = dr.Date
GROUP BY
dr.Date
ORDER BY
dr.Date
- 示例