你可以尝试这样的事情:
DATE '2006-05-20' + INTERVAL 5 DAY -> DATE '2006-05-25'
DATE '2006-05-20' + INTERVAL 5 MONTH -> DATE '2006-10-20'
DATE '2006-05-20' + INTERVAL 5 YEAR -> DATE '2011-05-20'
示例 1:
CREATE TABLE BEGIN_DATES
(
BDates DATETIME
);
INSERT INTO BEGIN_DATES VALUE ('13/08/2008');
INSERT INTO BEGIN_DATES VALUE ('13/02/2009');
INSERT INTO BEGIN_DATES VALUE ('13/08/2009');
INSERT INTO BEGIN_DATES VALUE ('15/02/2010');
INSERT INTO BEGIN_DATES VALUE ('13/08/2010');
INSERT INTO BEGIN_DATES VALUE ('14/02/2011');
INSERT INTO BEGIN_DATES VALUE ('15/08/2011');
INSERT INTO BEGIN_DATES VALUE ('13/02/2012');
INSERT INTO BEGIN_DATES VALUE ('13/08/2012');
INSERT INTO BEGIN_DATES VALUE ('13/02/2013');
INSERT INTO BEGIN_DATES VALUE ('13/08/2013');
INSERT INTO BEGIN_DATES VALUE ('13/02/2014');
INSERT INTO BEGIN_DATES VALUE ('13/08/2014');
INSERT INTO BEGIN_DATES VALUE ('13/02/2015');
SELECT BDates AS BEGIN, (BDates + INTERVAL 6 MONTH) AS END
FROM BEGIN_DATES
DROP TABLE BEGIN_DATES
示例 2:
BEGIN
SET @date = '2008-08-13';
SET @Edate ='2015-08-13';
WHILE @date <= @Edate DO
SELECT @date AS BEGIN_DATE, CAST(@date AS DATETIME) + INTERVAL 6 MONTH AS END_DATE; -- ADDDATE(@date,INTERVAL 6 MONTH)
SET @date = CAST(@date AS DATETIME) + INTERVAL 6 MONTH; -- Or ADDDATE(@date,INTERVAL 6 MONTH)
END WHILE;
END