简体   繁体   English

查找对话次数和每次对话的总时间

[英]find number of conversation and total time of each conversation

$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++;

}
OUTPUT
-----------------------------------------------------------------------------------
SL.No  Convo               Message                  Date               Duration
         ID
-----------------------------------------------------------------------------------
  2     137             Hi                      2012-08-30 10:29:59     0:0:21
  3     137             How are u?              2012-08-30 10:30:39     0:0:40
  4     137             Fine                    2012-08-30 10:31:05     0:0:26
  5     137             abc                     2012-08-30 15:05:50     2:16:49
  6     137             xyz                     2012-08-30 15:07:03     0:1:13
  7     137             bcc                     2012-08-30 15:07:39     0:0:36

If duration more than 10 mins consider as new conversation and note start time and end time of previous conversations. 如果持续时间超过10分钟,则视为新对话,并记下先前对话的开始时间和结束时间。

I need to find no. 我没有找到。 of conversation and total time for each conversation like. 对话和每次对话的总时间。

----------------------------------------------------------------------------------------
START                             END                          TOTAL TIME
----------------------------------------------------------------------------------------
2012-08-30 10:29:59        2012-08-30 10:31:05                   0.1.37
    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 

Use below query 使用以下查询

    SELECT conversation_id, MIN( `startDate` ) as START, MAX( `endDate` ) as END, SUM(`duration`) as TOTALTIME
    FROM `conversation_details`
    GROUP BY conversation_id

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM