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;
为什么开始日期 2012-12-21 和 2012-12-24 不存在,
如果 start_date 不存在,我需要一个 null 或空值
注意:我的数据库中没有 21 和 24 的记录,但我的结果中需要一个空值