gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 23:09:39 25 4
gpt4 key购买 nike

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

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

最佳答案

您需要为每一列做一个单独的 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

关于mysql - 查询 Shoretel 报告中的多个 SELECT CASE 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20405898/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com