找出一个时间区间内中断天数
应用场景
例:找出一个人这个月那几天断签了
sql
SELECT DISTINCT date_value
FROM (
SELECT DATE_ADD('2021-10-26', INTERVAL (t3*100 + t2*10 + t1) DAY) AS date_value
FROM
(SELECT 0 t1 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) t1,
(SELECT 0 t2 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) t2,
(SELECT 0 t3 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9) t3
WHERE DATE_ADD('2021-10-26', INTERVAL (t3*100 + t2*10 + t1) DAY) BETWEEN '2021-10-26' AND '2023-07-08'
) AS dates
WHERE NOT EXISTS (
SELECT 1
FROM task_bing_bg
WHERE DATE(created_at) = dates.date_value
)
ORDER BY date_value ASC;