我在下面的查询中使用了一个upsert,它在今天更新现有记录方面的工作基于'扩展'如果扩展名尚未存在于表格中,则添加新记录。
此查询在一天中汇总和更新总数,但是,我需要每天重新开始。因此,如果相同的6个代理商延期在线三天,他们的记录将全天更新,但我们最终会在三天结束时记录18条记录(历史报告)。
下面的查询在昨天工作得很好,但是现在它被覆盖了,因为重复的密钥是扩展名。我需要它来使用curdate更新当天的重复项,然后在第二天重新开始。
有关如何使用现有查询执行此操作的任何想法?
Insert into test.ambition_test(Extension, ExtID,
Total_Talk_Time_seconds,Total_Talk_Time_minutes,Total_Outbound, Total_Inbound,
Missed_Calls, Total_Calls, Time_of_report )
SELECT
c.extension as Extension
,RESPONSIBLEUSEREXTENSIONID as ExtID
, sum(Duration) as Total_Talk_Time_seconds
, round(sum(Duration) / 60,2) as Total_Talk_Time_minutes
, sum(if(LEGTYPE1 = 1,1,0)) as Total_Outbound
, sum(if(LEGTYPE1 = 2,1,0)) as Total_Inboundambition_test
, sum(if(Answered = 1,0,1)) as Missed_Calls
, count(DISTINCT b.NOTABLECALLID) as Total_Calls
, NOW()
FROM cdrdb.session a
LEFT JOIN cdrdb.callsummary b
ON a.NOTABLECALLID = b.NOTABLECALLID
LEFT join cdrdb.mxuser c
ON a.RESPONSIBLEUSEREXTENSIONID = c.EXTENSIONID
WHERE b.ts >= curdate()
AND c.extension IN (7295,7306,7218,7247,7330,7000,7358)
group by c.extension
ON duplicate key update Total_Talk_Time_seconds =
values(Total_Talk_Time_seconds), Total_Talk_Time_minutes =
values(Total_Talk_Time_minutes), Total_Outbound = values(Total_Outbound),
Total_Inbound = values(Total_Inbound)
, Missed_calls = values(Missed_Calls), Total_Calls = values(Total_Calls),
Time_of_report = values(Time_of_report);
更新
按键图片: