gpt4 book ai didi

php - 每天不重叠的分钟数

转载 作者:行者123 更新时间:2023-11-30 22:15:37 25 4
gpt4 key购买 nike

我一直在绞尽脑汁想解决这个问题。

我需要知道店内一名员工单独一天工作了多少分钟。

这是 daynumber = 0(星期一)的数据:

table data - example

对于这一天,staffid = 32 的工作人员从 11:00 到 11:05 独自在店里。

到目前为止,我只是将所有开始时间相加,但基本上我在想的是,如果我有任何办法知道一名工作人员是独自一人,我可以计算索引和下一个之间的时间。

for($i=0; $i<count($results); $i++){
if(isset($results[$i+1])){
if($results[$i]->starttime < $results[$i+1]->starttime)
$start = strtotime($results[$i]->starttime);
$end = strtotime($results[$i+1]->endtime);
$minutes += idate('i', $end - $start);
}
}
}

有什么想法吗?

更新 1:我做到了这一点,但仍然没有运气;

    for($i=0; $i<count($results); $i++){
if(isset($results[$i+1])){
$StartDate1 = strtotime($results[$i]->starttime);
$EndDate1 = strtotime($results[$i]->endtime);
$StartDate2 = strtotime($results[$i+1]->starttime);
$EndDate2 = strtotime($results[$i+1]->endtime);

if(($StartDate1 <= $EndDate2) && ($EndDate1 >= $StartDate2)){
$StartDate1 = idate('i', $StartDate1);
$EndDate1 = idate('i', $EndDate1);
$StartDate2 = idate('i', $StartDate2);
$EndDate2 = idate('i', $EndDate2);

$a = abs($EndDate1 - $StartDate1);
$b= abs($EndDate1 - $StartDate2);
$c = abs($EndDate2 - $StartDate2);
$d = abs($EndDate2 - $StartDate1);

$minutes += min([$a,$b,$c,$d]);
}
}
}

我做错了什么?

最佳答案

这是一个想法,使用实用程序表 - 在本例中是 0-9 的整数表。 有些人不喜欢实用表,但我喜欢它们,因为它们意味着更少的打字。 您始终可以用 UNION 字符串替换该表。

这是所有天。稍后我可能会对其进行修改,以展示如何针对特定日期进行过滤。

SELECT * FROM ints;
+---+
| i |
+---+
| 0 |
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 6 |
| 7 |
| 8 |
| 9 |
+---+

SELECT SEC_TO_TIME((i4.i*1000+i3.i*100+i2.i*10+i1.i)*60) n
FROM ints i1
JOIN ints i2
JOIN ints i3
JOIN ints i4
JOIN
( SELECT daynumber
, MIN(starttime) starttime
, MAX(CASE WHEN endtime < starttime THEN SEC_TO_TIME(TIME_TO_SEC('24:00:00')+TIME_TO_SEC(endtime)) ELSE endtime END) endtime
FROM my_table
GROUP
BY daynumber
) x
ON SEC_TO_TIME((i4.i*1000+i3.i*100+i2.i*10+i1.i)*60) BETWEEN x.starttime AND x.endtime
JOIN my_table y
ON SEC_TO_TIME((i4.i*1000+i3.i*100+i2.i*10+i1.i)*60) BETWEEN y.starttime AND CASE WHEN y.endtime < y.starttime THEN SEC_TO_TIME(TIME_TO_SEC('24:00:00')+TIME_TO_SEC(y.endtime)) ELSE y.endtime END
GROUP
BY n HAVING COUNT(*) = 1;

The number of lone minutes is equal to the number of rows in this result.

关于php - 每天不重叠的分钟数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38403082/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com