我有这个MySQL查询告诉我状态更改条目之间的区别:
SELECT
t1.`TRACKID` AS TicketNumber,
TIMEDIFF(t2.`date`, t1.`date`) AS Difference
FROM
hesk_history t1
JOIN hesk_history t2 ON t2.`TRACKID` = t1.`TRACKID` AND t1.`Action` = 'Created' AND (t2.`Action` = 2)
给我以下结果集:
TicketNumber Difference
2013-08-12-36 410:21:25
2013-06-12-91 00:01:22
2013-08-12-50 00:00:26
我如何AVG这个结果集?
答案 0 :(得分:0)
http://www.w3schools.com/sql/sql_func_avg.asp 所以在你的情况下
选择
AVG(t1。TRACKID
AS TicketNumber,
TIMEDIFF(t2。date
,t1。date
))AS差异
从
hesk_history t1
加入hesk_history t2 ON t2。TRACKID
= t1。TRACKID
AND t1。Action
='已创建'AND(t2。Action
= 2)