Mysql -如何通过使用开始日期和持续时间计算结束日期



在查询中,在BU_START_DATE和BU_DURATION的帮助下,我想计算END_DATE .这里持续时间以月表示。假设BU_START_DATE为2014-05-23 t13:10:01. 15, BU_DURATION为2,则END_DATE的计算结果应为2014-07-23 t13:10:01. 15

SELECT A.PROJECT_ID,A.PROJECT_BASIC_INFORMATION_ID,B.VALUE AS BU_START_DATE,C.VALUE AS BU_DURATION
FROM 
PROJECT_BASIC_INFORMATION A,
CUSTOM_ATTRIBUTES_VALUES B,
CUSTOM_ATTRIBUTES_VALUES C
WHERE 
A.TENANT_ID = '100' AND
B.MAP_ID = (SELECT MST_ATTRIBUTE_ID FROM `MST_TENANT_CUSTOM_ATTRIBUTES` 
WHERE LABEL='Budget Project Savings Start Date' AND 
TENANT_ID='100')
AND
C.MAP_ID = (SELECT MST_ATTRIBUTE_ID FROM `MST_TENANT_CUSTOM_ATTRIBUTES` 
WHERE LABEL='Budget Savings Duration' AND 
TENANT_ID='100')
GROUP BY A.PROJECT_BASIC_INFORMATION_ID ORDER BY A.PROJECT_ID;

谢谢。

使用mysql date_add()就可以了。

mysql> select date_add('2014-05-23T13:10:01.515', INTERVAL 2 month);
+-------------------------------------------------------+
| date_add('2014-05-23T13:10:01.515', INTERVAL 2 month) |
+-------------------------------------------------------+
| 2014-07-23 13:10:01.515000                            |
+-------------------------------------------------------+

在查询语句中添加

date_add(BU_START_DATE, INTERVAL BU_DURATION month) as END_DATE 

相关内容

  • 没有找到相关文章

最新更新