這是常見到的需求.
我們先建立測試Table
CREATE TABLE iron1004(
task_id TINYINT NOT NULL PRIMARY KEY,
start_date DATE NOT NULL,
end_date DATE NOT NULL
);
INSERT INTO iron1004 VALUES
(1, '2014-01-01', '2014-01-03'),
(2, '2014-01-02', '2014-01-04'),
(3, '2014-01-04', '2014-01-05'),
(4, '2014-01-06', '2014-01-09'),
(5, '2014-01-09', '2014-01-09'),
(6, '2014-01-09', '2014-01-09'),
(7, '2014-01-12', '2014-01-15'),
(8, '2014-01-13', '2014-01-14'),
(9, '2014-01-14', '2014-01-14'),
(10, '2014-01-17', '2014-01-17');
我們想要得到以下的結果:
+------------+------------+
| start_date | end_date |
+------------+------------+
| 2014-01-01 | 2014-01-05 |
| 2014-01-06 | 2014-01-09 |
| 2014-01-12 | 2014-01-15 |
| 2014-01-17 | 2014-01-17 |
+------------+------------+
試試看你是否能夠解答出來呢?