计算每两个记录之间的时间差
澳门新葡京官网
澳门新葡京官网
当前位置 : 澳门新葡京官网 > 新葡京娱乐场

计算每两个记录之间的时间差

想计算每两个记录之间的时间差 如

#查询某一用户该日抽奖时间
select draw_time from user_draw_log where user_id = 1 and draw_date=2016-03-09 order by id;
+---------------------+
| draw_time           |
+---------------------+
| 2016-03-09 13:52:46 |
| 2016-03-09 13:52:53 |
| 2016-03-09 13:53:01 |
| 2016-03-09 13:53:13 |
| 2016-03-09 13:53:25 |
...

想计算每次抽奖时间之间的间隔 以便判断是否是并发插入 我的方法如下
使用一个临时变量记录前一次的抽奖时间

select draw_time, timediffdraw_time,@prev_time diff,@prev_time:=draw_time from user_draw_log where user_id = 1 and draw_date=2016-03-09 order by id;
+---------------------+------------------+-------------------------+
| draw_time           | diff             | @prev_time:=draw_time |
+---------------------+------------------+-------------------------+
| 2016-03-09 13:52:46 | -00:08:28.000000 | 2016-03-09 13:52:46     |
| 2016-03-09 13:52:53 | 00:00:07.000000  | 2016-03-09 13:52:53     |
| 2016-03-09 13:53:01 | 00:00:08.000000  | 2016-03-09 13:53:01     |
| 2016-03-09 13:53:13 | 00:00:12.000000  | 2016-03-09 13:53:13     |
| 2016-03-09 13:53:25 | 00:00:12.000000  | 2016-03-09 13:53:25     |
| 2016-03-09 13:53:32 | 00:00:07.000000  | 2016-03-09 13:53:32     |
| 2016-03-09 13:53:38 | 00:00:06.000000  | 2016-03-09 13:53:38     |
...

有没更方便的方法实现这一功能呢?

栏目列表

广告位

澳门新葡京官网