0

一个表具有以下数据条目:

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" 
)

现在,我正在寻找的是一种选择与当前日期匹配的条目的方法。

/拉尔斯

4

1 回答 1

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 为我迭代间隔。但是,唉,我只得到了第一次迭代。

也许是存储过程或?

于 2013-07-16T05:39:23.547 回答