2013-07-15 59 views
0

的表具有以下數據項:SQL語句

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

你可以用一些例子來說明你的問題。對於你列出的一行,這是間隔'2013-07-15 08:22'到'2013-07-22 03:55'?這不完全是一個星期嗎? – Andomar

+0

其中mm_start_date> =當前日期和mm_end_hour <= 23:59且mm_interval_type = 1 – vels4j

+0

您是否可以修改架構? – Strawberry

回答

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 

這是它得到....

我的想法是使用之間來遍歷我的時間間隔。但是,唉,我只得到第一次迭代。

也許存儲過程還是?

+0

似乎這個問題不能由MySql處理。 – osomanden