查询Shoretel报告中的多个SELECT CASE语句

时间:2013-12-05 16:51:37

标签: mysql sql reporting-services bids shoretel

我正在尝试执行一个允许视图中有多个列的查询。任何帮助都会有所帮助。

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 个答案:

答案 0 :(得分:0)

您需要为每列执行单独的case语句:

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

这会产生如下输出:

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