数据库表user_go
id updatetime gotype
1 2008-12-1 00:00 in
1 2008-12-1 12:00 out
2 2008-12-1 00:01 in
1 2008-12-1 13:00 in
1 2008-12-1 14:00 out
2 2008-12-1 15:00 out现在想计算出
id 为1的用户 的两次in out时间的差值和
select * from user_go where id=1; 读取出来四条记录
但不知道如何 去计算 差值!本人是在mysql 5.0 的存储过程中计算 本来准备用 上一条记录 和下一条记录的模式来写,但没有找到mysql中有类似的方法。郁闷!请高人帮忙!
id updatetime gotype
1 2008-12-1 00:00 in
1 2008-12-1 12:00 out
2 2008-12-1 00:01 in
1 2008-12-1 13:00 in
1 2008-12-1 14:00 out
2 2008-12-1 15:00 out现在想计算出
id 为1的用户 的两次in out时间的差值和
select * from user_go where id=1; 读取出来四条记录
但不知道如何 去计算 差值!本人是在mysql 5.0 的存储过程中计算 本来准备用 上一条记录 和下一条记录的模式来写,但没有找到mysql中有类似的方法。郁闷!请高人帮忙!
select (select sum(unix_timestamp(updatetime)) where gotype='out')-(select sum(unix_timestamp(updatetime)) where gotype='in')