I have a problem, my query isn't working properly
SELECT * FROM a
LEFT JOIN b on a.eid = b.id
LEFT JOIN c ON a.cid = c.id
WHERE
DAYOFYEAR(a.start) BETWEEN :startdate_day_of_year AND :enddate_day_of_year
AND
:开发者_StackOverflow中文版year BETWEEN a.start AND a.end
:startdate_day_of_year and :enddate_day_of_year are passed from the user input... 1-365 :year is passed from the user input...2011
The problem is that an event can recur every year (ie: event started in 2008 and goes through 2012). It has to display the event every year...
When I've added table c to the mix i started getting limited results... if i replaced the where part with the fixed dates instead of dayofyear and year it started working the way it should... but then i cannot get the recurring events.
Thannk you! BR
Recurring events are rather different from non-recurring events. If recurring events had e.g. year of beginning and year of end, I'd have a separate table for recurring events.
Else, I'd have a Boolean column is_yearly_event
and would only check year if it is not set:
...AND (a.is_yearly_event != 0 OR :year BETWEEN a.start AND a.end)
精彩评论