我需要一些帮助来改变我的查询,
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不存在,那么我需要
的空值或空值谢谢我提前
注意:我的数据库中没有21和24 ..的记录,但我的查询中需要一个空值
答案 0 :(得分:1)
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'
OR t1.start_date IS NULL -- <<< I assume this is what you want...
GROUP BY
t1.eventId,t1.start_date
ORDER BY
t1.start_date,pos ASC
) t
WHERE
pos <= 3;