我有一个准确且有效的查询来提取CSR电话数据,但我一直只在一个CSR扩展上测试它。现在它正在运行,我想将它应用于所有15个CSR。
查询:
SELECT
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) and ANSWERED = 1) AS total_inbound
FROM cdrdb.session a
INNER JOIN cdrdb.callsummary b
ON a.NOTABLECALLID = b.NOTABLECALLID
where date(b.ts) >= curdate()
AND 7200 in (callingpartyno, finallycalledpartyno);
但是,我想修改我的where子句,而不是说“选择哪里扩展7200在callingpartyno和finallycalledpartyno”它会说select the calls where (7276,7314,7295,7306,7357,7200,7218,7247,7331,7255,7330,7000,7215,7240,7358,7312) IN (callingpartyno, finallycalledpartyno)
但我知道语法不会起作用,因为它会产生15列。
以下是一些快速构思的示例数据:
callingpartyno | finallycalledpartyno
-------------------------------------
1234 outside
1234 outside
1234 outside
outsidecall 1234
outsidecall 1234
outsidecall 1234
9876 outside
9876 outside
9876 outside
outsidecall 9876
outsidecall 9876
outsidecall 9876
例如,扩展1234有6个调用,但在表中你只能通过包含这两个列来知道。
将查询应用于该扩展数组的最佳/最准确和最高效的方法是什么?
答案 0 :(得分:2)
每列重复列表,例如
select *
from calls
where callingpartyno IN (7276,7314, 7295, 7306,7357,7200,7218,7247 7331,7255,7330,7000,7215, 7240,7358,7312)
OR finallycalledpartyno IN (7276,7314, 7295, 7306,7357,7200,7218,7247 7331,7255,7330,7000,7215, 7240,7358,7312)