我有一张包含票据用法日志的表格。如何将连续两行分组以获得持续时间? 例如:前4行我应该
ticket_id duration
15874 03:03:31
15874 01:10:35
答案 0 :(得分:0)
我已经创建了一个示例,结果将显示GROUP BY
使用datetime
和UserID的日期:
SELECT start_log.UserID, TIME(start_log.created_id), TIME(end_log.created_id),
DATE(start_log.created_id), TIMESTAMPDIFF(
MINUTE , start_log.created_id, end_log.created_id ) AS TimeInMin
FROM sample AS start_log
INNER JOIN sample AS end_log ON (start_log.UserID = end_log.UserID
AND start_log.created_id < end_log.created_id )
GROUP BY TIME(start_log.created_id), UserID
输出我的意思是持续时间以分钟为单位:更新