0

我可以使用此工作查询获得以下结果:

$query = "SELECT tt.time_start, tt.time_end
FROM track_time as tt, project_track as pt, project_clients as pc, clients as cl
WHERE tt.track_id = pt.track_id
AND pt.project_id = pc.project_id
AND pc.client_id = cl.client_id
AND cl.client_id =".$db->prep($client_id);
$res = $db->query($query,'assoc');

**RESULTS**
time_start  time_end    client_id
1340927940  1340928420  1
1341066240  1341077040  1
1341086400  1341088560  1
1340954400  1340986800  7

我要为每个客户实现的目标是将它们的所有time_start值相加得到一个结果,将它们的所有time_end值相加得到一个结果,然后得到这两个结果之间的差异。这将使我能够确定每个客户的总数。

我正在使用 PHP 并尝试所有的 foreach 方式,但没有运气和不正确的数组返回。有任何想法吗?

4

2 回答 2

1

试试这个:

$query = "SELECT pc.client_id, 
                 (SUM(tt.time_start) - SUM(tt.time_end)) as `Difference`
          FROM  track_time as tt, project_track as pt, 
                project_clients as pc, clients as cl
          WHERE tt.track_id = pt.track_id
                    AND pt.project_id = pc.project_id
                    AND pc.client_id = cl.client_id
                    AND cl.client_id =" . $db->prep($client_id) . " 
          GROUP BY client_id";
于 2012-07-01T00:21:54.387 回答
0

time_start并且time_end似乎是时间戳值。所以 ;

$total = 0;
foreach( $array as $item)
{
     $total += strtotime( $item['time_start']);
}

在那之后,如果你date()以有意的格式运行一个函数,我认为它应该可以正常工作。

于 2012-06-30T23:14:45.227 回答