我具有以下日志表,因为我想获取错误日志持续时间,即开始时间,结束时间和总持续时间
log_Name date_time
ok 2019-01-31 12:20:02
ok 2019-01-31 12:20:18
err1 2019-01-31 12:20:20
err1 2019-01-31 12:20:40
err2 2019-01-31 12:20:50
err2 2019-01-31 12:20:59
err2 2019-01-31 12:21:05
err1 2019-01-31 12:21:10
err1 2019-01-31 12:21:40
err3 2019-01-31 12:21:50
err3 2019-01-31 12:21:58
err2 2019-01-31 12:22:10
err2 2019-01-31 12:24:28
我想得到以下结果
log_Name start_time end_time duration
err1 2019-01-31 12:20:20 2019-01-31 12:20:40 00:00:20
err2 2019-01-31 12:20:50 2019-01-31 12:21:05 00:00:15
err1 2019-01-31 12:21:10 2019-01-31 12:21:40 00:00:30
err3 2019-01-31 12:21:50 2019-01-31 12:21:58 00:00:08
err2 2019-01-31 12:22:10 2019-01-31 12:24:28 00:02:18
我尝试了以下查询,但我找不到正确的方法来获取结果查询,请指导我获取正确的结果
SELECT m.log_Name as log_Nam,m.date_time as start_time FROM test as m UNION SELECT n.date_time as end_time FROM test n where m.log_Name!='ok'