SQL Shortel Abandoned Calls Query

时间:2013-12-05 15:20:30

标签: mysql sql reporting-services case shoretel

我想查询一个表,它似乎没有工作。有人可以帮忙吗?

SELECT     ExitReason AS CallsAbandoned
FROM         queuecall
WHERE     (ExitReason = 7) THEN
                  (ExitReason = 1 ELSE
                  (ExitReason = 0)))

我正在寻找的定义或结果是:

if {ExitReason} = 7 THEN 1 ELSE 0

我不确定正确的查询有多完整。

谢谢, 阿龙

2 个答案:

答案 0 :(得分:1)

您正在寻找以下内容:

SELECT CASE WHEN ExitReason = 7 
       THEN 1 
       ELSE 0 
       END AS CallsAbandoned 
FROM queuecall

或者,如果您想要计算CASE的结果,请尝试以下方法:

SELECT SUM(CASE WHEN ExitReason = 7 
       THEN 1 
       ELSE 0 
       END) AS CallsAbandoned 
FROM queuecall

答案 1 :(得分:0)

试试这个:

 SELECT IF(EXITREASON = 7, 1, 0) AS CallsAbandoned 
FROM   QUEUECALL 

SQL FIDDLE : http://sqlfiddle.com/#!2/56a1d/1