Multiple SELECT CASE statements in Query For Shoretel Reports

。_饼干妹妹 提交于 2019-12-11 06:46:08

问题


I am trying to do a query that allow for multiple columns in a view. Any assistance would be helpful.

SELECT  queuecall1.StartTime, queuecall1.QueueName
CASE 
    WHEN ExitReason = 7 THEN 1 ELSE 0 END AS CallsAbandoned
    WHEN ExitReason = 1 THEN 1 ELSE 0 END AS CallsAgent 
    WHEN calltype = 1 THEN 1 ELSE 0 END) AS CallsInternal 
    WHEN calltype = 2 THEN 1 ELSE 0 END) AS CallsExternal
FROM   (queuecall queuecall1 INNER JOIN connect connect1 
ON queuecall1.ConnectTableID=connect1.ID) INNER JOIN call call1 
ON connect1.CallTableID=call1.ID

回答1:


You need to do a separate case statement for each column:

SELECT  queuecall1.StartTime, 
        queuecall1.QueueName,
        CASE WHEN ExitReason = 7 THEN 1 ELSE 0 END AS CallsAbandoned,
        CASE WHEN ExitReason = 1 THEN 1 ELSE 0 END AS CallsAgent,
        CASE WHEN calltype = 1 THEN 1 ELSE 0 END AS CallsInternal,
        CASE WHEN calltype = 2 THEN 1 ELSE 0 END AS CallsExternal
FROM   (queuecall queuecall1 INNER JOIN connect connect1 
ON queuecall1.ConnectTableID=connect1.ID) INNER JOIN call call1 
ON connect1.CallTableID=call1.ID

This would give an output like:

StartTime | QueueName | CallsAbandoned | CallsAgent | CallsInternal | CallsExternal
----------+-----------+----------------+------------+---------------+---------------
 10:59    |  Queue1   |      1         |    0       |     1         |      0
 11:05    |  Queue1   |      1         |    0       |     1         |      0
 11:11    |  Queue1   |      0         |    1       |     1         |      0
 11:12    |  Queue1   |      0         |    0       |     0         |      1
 11:24    |  Queue1   |      0         |    1       |     0         |      1
 11:37    |  Queue1   |      1         |    0       |     0         |      1
 11:42    |  Queue1   |      0         |    1       |     0         |      0


来源:https://stackoverflow.com/questions/20405898/multiple-select-case-statements-in-query-for-shoretel-reports

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!