在日期范围中包含零值的日期

时间:2012-12-19 12:36:38

标签: mysql gaps-and-islands

My db records

SELECT * FROM (
    SELECT t1.eventId,t1.start_date,t1.end_date, COUNT(*) pos FROM events t1
    LEFT JOIN events t2 ON t1.start_date = t2.start_date AND t1.eventId <= t2.eventId
    WHERE t1.start_date BETWEEN  '2012-12-18' AND '2012-12-24'
    GROUP BY t1.eventId,t1.start_date
    ORDER BY t1.start_date,pos ASC
    ) t
WHERE pos <= 3;

enter image description here

为什么开始日期2012-12-21和2012-12-24不存在,

如果start_date不存在,那么我需要

的空值或空值

注意:我的数据库中没有21和24 ..的记录,但我的结果中需要一个空值

0 个答案:

没有答案