0
$query=mysql_query("SELECT @rownum := @rownum + 1 AS id,t.convo_id,t.body_xml,FROM_UNIXTIME(t.timestamp) FROM messages t,(SELECT @rownum := 0) r WHERE t.convo_id='137'");

$recordset = array(); 

$i = 0;

while ($row = mysql_fetch_array($query))

{

       $recordset[$i] = $row;
    if ($i > 0) 
    { 
        $recordset[$i-1]['nextid'] = $row['0']; 
        $datetime1 = new DateTime($recordset[$i-1][3]);
        $datetime2 = new DateTime($recordset[$i][3]);

        $interval = $datetime1->diff($datetime2);
        $hours   = $interval->format('%h');
        $minutes = $interval->format('%i');
        $seconds = $interval->format('%s');
        ?>
        <tr>
            <td><?php echo $row[0];?></td>
            <td><?php echo $row[1];?></td>
            <td><?php echo $row[2];?></td>
            <td><?php echo $row[3];?></td>
            <td><?php echo  $hours .":".$minutes.":".$seconds ?></td>
           <?php

     }

    $i++;

}
输出
-------------------------------------------------- ---------------------------------
SL.No Convo 消息日期持续时间
         ID
-------------------------------------------------- ---------------------------------
  2 137 你好 2012-08-30 10:29:59 0:0:21
  3 137 你好吗?2012-08-30 10:30:39 0:0:40
  4 137 罚款 2012-08-30 10:31:05 0:0:26
  5 137 美国广播公司 2012-08-30 15:05:50 2:16:49
  6 137 xyz 2012-08-30 15:07:03 0:1:13
  7 137 密件抄送 2012-08-30 15:07:39 0:0:36

如果持续时间超过 10 分钟,则视为新对话,并记下先前对话的开始时间和结束时间。

我需要找到没有。对话的总时间和每次对话的总时间。

-------------------------------------------------- --------------------------------------
开始结束总时间
-------------------------------------------------- --------------------------------------
2012-08-30 10:29:59 2012-08-30 10:31:05 0.1.37
4

2 回答 2

1
    SELECT @rownum := @rownum + 1 AS id,t.convo_id,t.body_xml,
         str_to_date(min(t.timestamp),'%y%m%d')as
         start,str_to_date(max(t.timestamp),'%y%m%d') as 
end,sum(str_to_date(t.timestamp),'%i')as    duration FROM
         messages t,(SELECT @rownum := 0) r WHERE t.convo_id='137' group by t.convo_id 
于 2012-10-17T06:37:47.973 回答
0

使用以下查询

    SELECT conversation_id, MIN( `startDate` ) as START, MAX( `endDate` ) as END, SUM(`duration`) as TOTALTIME
    FROM `conversation_details`
    GROUP BY conversation_id
于 2012-10-17T06:12:58.513 回答