目标:计算座席每天在每个广告系列中花费的总时间。 问题:使用最小值和最大值结束"不正确"结果。 当前查询:
SELECT agent,campaign,DATE(eventfield) AS created,TIMESTAMPDIFF(SECOND,MIN(TIMESTAMP(eventfield)),MAX(TIMESTAMP(eventfield))) / 3600 AS Hours
FROM log1
WHERE eventfield > '2015-01-19'
AND eventfield < '2015-01-20'
GROUP BY agent,campaign,created
示例数据:
agent campaign eventfield
alfalfa apples 2015-01-19 09:00:00
alfalfa apples 2015-01-19 09:11:00
alfalfa pears 2015-01-19 09:11:00
alfalfa pears 2015-01-19 16:30:00
alfalfa apples 2015-01-19 16:30:00
alfalfa apples 2015-01-19 17:00:00
预期结果:
agent campaign created hours
alfalfa apples 2015-01-19 0.6833
alfalfa pears 2015-01-19 7.3167
实际结果:
agent campaign created hours
alfalfa apples 2015-01-19 8.0000
alfalfa pears 2015-01-19 7.3167