如何在mysql

时间:2015-07-13 11:50:12

标签: mysql

这是我的疑问:

SELECT (HOUR(TIMEDIFF(i.StartTime,'18:30:00'))*60) + MINUTE(TIMEDIFF(i.StartTime,'18:30:00')) AS f_day,
        (HOUR(TIMEDIFF(i.StartTime,i.EndTime))*60) + MINUTE(TIMEDIFF(i.StartTime,i.EndTime)) AS current,
        i.StartDate, i.EndDate, i.StartTime, i.EndTime, i.id
    FROM `request` r 
    INNER JOIN `interval` i ON r.id = i.requestId
    WHERE r.userId ='xxxx' 

    AND r.eventId = '5' AND r.statusId = '2'

    ORDER BY i.StartDate ASC

这就是结果:enter image description here

有没有办法检查工作日是否连续10次? 例如,在我的情况下,结果应该是最后2行 2015-07-28 --- 2015-07-30 => 3天和2015-07-31 --- 2015-08-10 => 7天。所以这是连续10天

1 个答案:

答案 0 :(得分:0)

应该足够简单:

SELECT DATEDIFF(EndDate, StartDate)+1 AS consecutive_days;

返回

EndDate    | StartDate  | consecutive_days
2015-07-30 | 2015-07-28 |                3
2015-08-10 | 2015-07-31 |               11