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