一个表包含以下数据条目:
mm_id, mm_interval, mm_interval_type, mm_start_date, mm_start_hour, mm_end_hour
3, 14, 3, 2013-07-15, 08:22, 03:55
mm_interval是“每个” mm_interval_type是
array(
1=>"Hour",
2=>"Day",
3=>"Week",
4=>"Month",
5=>"Year"
)
现在,我正在寻找的是一种选择与当前日期匹配的条目。
/拉斯
答案 0 :(得分:0)
我想我会用结果来改变这个问题; - )
SELECT
mm.*,
mm_recurrence_settings.*
FROM
mm
LEFT JOIN mm_types USING (mm_type_id)
LEFT JOIN mm_recurrence_settings USING (mm_id)
WHERE
SELECT
CASE
WHEN mm_recurrence_settings.mm_reoc_interval_type = 1 THEN DATE(NOW()) BETWEEN DATE(DATE_ADD(mm_recurrence_settings.mm_reoc_start_date, INTERVAL mm_recurrence_settings.mm_reoc_interval HOUR)) AND CURDATE( )
WHEN mm_recurrence_settings.mm_reoc_interval_type = 2 THEN DATE(NOW()) BETWEEN DATE(DATE_ADD(mm_recurrence_settings.mm_reoc_start_date, INTERVAL mm_recurrence_settings.mm_reoc_interval DAY)) AND CURDATE( )
WHEN mm_recurrence_settings.mm_reoc_interval_type = 3 THEN DATE(NOW()) BETWEEN DATE(DATE_ADD(mm_recurrence_settings.mm_reoc_start_date, INTERVAL mm_recurrence_settings.mm_reoc_interval WEEK)) AND CURDATE( )
WHEN mm_recurrence_settings.mm_reoc_interval_type = 4 THEN DATE(NOW()) BETWEEN DATE(DATE_ADD(mm_recurrence_settings.mm_reoc_start_date, INTERVAL mm_recurrence_settings.mm_reoc_interval MONTH)) AND CURDATE( )
WHEN mm_recurrence_settings.mm_reoc_interval_type = 5 THEN DATE(NOW()) BETWEEN DATE(DATE_ADD(mm_recurrence_settings.mm_reoc_start_date, INTERVAL mm_recurrence_settings.mm_reoc_interval YEAR)) AND CURDATE( )
END as newDate
这就是它的所在......
我的想法是使用BETWEEN迭代我的间隔。但是,唉,我只进行了第一次迭代。
也许是存储过程或?