简体   繁体   English

Where子句在两列之一中搜索15个不同的值

[英]Where clause to search for 15 different values in one of two columns

I have an accurate and working query, to pull CSR phone data, but I've been testing it only on one CSR extension. 我有一个准确且有效的查询来提取CSR电话数据,但我仅在一个CSR扩展程序上对其进行了测试。 Now that it's working, I want to apply it to all 15 CSRs. 现在它正在运行,我想将其应用于所有15个CSR。

The query: 查询:

 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);

However, I want to modify my where clause so instead of it saying "select where extension 7200 is in callingpartyno and finallycalledpartyno" It would say select the calls where (7276,7314,7295,7306,7357,7200,7218,7247,7331,7255,7330,7000,7215,7240,7358,7312) IN (callingpartyno, finallycalledpartyno) 但是,我想修改我的where子句,而不是说“选择在callingpartyno和finallycallpartyno中选择分机7200的位置”,而是要select the calls where (7276,7314,7295,7306,7357,7200,7218,7247,7331,7255,7330,7000,7215,7240,7358,7312) IN (callingpartyno, finallycalledpartyno)

But I know that syntax won't work because it would expect 15 columns. 但是我知道语法将不起作用,因为它将需要15列。

Here's some sample data for a quick idea: 以下是一些简单的示例数据:

    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      

For instance, extension 1234 has 6 calls, but in the table you would only know that by including both of those columns. 例如,分机1234有6个呼叫,但是在表中,只有将这两个列都包括在内,您才能知道。

What's the best/most accurate and performant way for me to apply my query to that array of extensions? 我将查询应用于该扩展数组的最佳/最准确和高效的方法是什么?

Repeat the list per column, eg 重复每列的列表,例如

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) 

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

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