2016-02-22 61 views
0

編輯:我有一個表的開始和結束時間字段。我會將常用時間間隔分組。這是可能的?記錄之間的平均間隔

假設這個表:

time_begin time_end 
07:00  18:00 
09:00  12:00 (this interval is in the first line) 
17:00  18:00 (this interval is in the first line) 

我想回行:

time_begin time_end 
09:00  12:00 
17:00  18:00 

感謝

+1

很好。祝你好運。你有編程問題嗎?這個網站是問題,而不是轉儲您的待辦事項/需求清單的地方。 –

+0

我試圖更好地解釋我的疑問。 –

回答

0

嘗試此查詢。

SELECT time_begin, time_end 
FROM table_name 
WHERE time_begin < (SELECT time_end 
        FROM table_name 
        LIMIT 1) 
AND time_begin > (SELECT time_begin 
        FROM table_name 
        LIMIT 1) 
AND time_end < (SELECT time_end 
        FROM table_name 
        LIMIT 1) 
AND time_end > (SELECT time_begin 
        FROM table_name 
        LIMIT 1) 

該查詢返回第一行中時間間隔之間的所有時間間隔。