获得两个相同日期MYSQL的区别

时间:2015-03-11 14:17:15

标签: php mysql

嗨,大家好,我的代码是:

SELECT SUM(DATEDIFF(L_End, L_Start)), L_Start,L_End
        FROM leave_table 
        where ID_No = '9283158370' and L_Status = 'Approve' and L_Type ='Sick'

这是有效的但是我的困境是如果开始和结束日期是相同的,例如开始日期是2015-03-10,结束日期也是2015-03-10。如果我在DATEDIFF函数中查询差异为0.我希望日期差异等于 1 。因为它的开始和结束日期是1天。

1 个答案:

答案 0 :(得分:1)

你需要这样的东西:

SELECT SUM(CASE WHEN DATEDIFF(L_End, L_Start) = '0' THEN 1 ELSE DATEDIFF(L_End, L_Start) END) as summed_column, L_Start,L_End
    FROM leave_table 
    where ID_No = '9283158370' and L_Status = 'Approve' and L_Type ='Sick'