取两条相邻数据之间的时间差
SELECT A.id,A.createDate,B.createDate,
TIMESTAMPDIFF(MINUTE,A.createDate,B.createDate) mins
FROM(
SELECT a.*,(@i := @i + 1) AS ord_num FROM ${tableName} a,(SELECT @i := 1) d ORDER BY a.createDate
) AS A
LEFT JOIN (
SELECT a.*,(@j := @j + 1) AS ord_num FROM ${tableName} a,(SELECT @j := 0) c ORDER BY a.createDate
)AS B ON A.ord_num=B.ord_num
TIMESTAMPDIFF 取时间差 TIMESTAMPDIFF (SECOND,date1,date2)
秒 :SECOND
分:MINUTE
小时:HOUR
天数:DAY