两行之间的时差 - mysql [英] time difference between two rows - mysql
本文介绍了两行之间的时差 - mysql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否有任何方法可以计算两行之间的时间差.我想计算名称 -> 测试等的时间差.名称可以按任何顺序排列.
I wanted to know if there is any way where i can calculate time difference between two rows. I want to calculate time difference for name -> test etc. The name can be in any order.
我想知道测试是否在第 1 行和第 3 行然后在第 7 行和第 11 行有两次,我可以计算这些行之间的时间差吗?即第 1 行和第 3 行,其他第 7 行和第 11 行.
I want to know if test has two times at row 1 and 3 and then at row 7 and 11, can i calculate time difference between these rows? i.e for row 1 and 3, and other for row 7 and 11.
下面有我的数据库的图片
below image with my database
推荐答案
如果你想检查 PHP 的差异,你可以这样做.
If you want to check the difference in PHP you can do something like this.
function secondsBetweenRows($first, $second)
{
return strtotime($second->entered_at) - strtotime($first->entered_at);
}
// group rows by users
$users = []
foreach ($rows as $row) {
$users[$row->name] = $row;
}
// check row difference
$timeDiff = [];
foreach ($users as $userName => $userRows) {
// assume there are always to, if not do some checks here
$timeDiff[$userName] = secondsBetweenRows($userRows[1], $userRows[0]);
}
print_r($timeDiff);
/*
Array
(
[test] => 24
[test1] => 26
)
*/
这篇关于两行之间的时差 - mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文