满足条件时的SQL计数

问题描述 投票:0回答:1

抱歉,这似乎是一个愚蠢的问题,但是我对SQL还不陌生,我正在运行ODBC并在Excel中使用超级查询。我希望例如将以下内容作为列(这是从AWS CTR中提取的)。队列来电到达日期提供的电话已接来电已接来电(在指定时间内)

我发现很难将已回答的呼叫作为一列,下面是我正在运行的当前语句,并且出现错误,如果删除“已回答的呼叫”语句,查询将按预期工作。任何对此的建议将不胜感激。

SELECT queue.name as "queue", cast(substring(connectedtosystemtimestamp,1,10) as date) as "call arrival date", count(contactid) as "Calls Offered", count(case when(cast(queue.duration as integer)<30) then 1 end) as "answered below 30 sec", SUM(CASE initiationmethod=’INBOUND’, name IS NOT NULL AND agent IS NOT NULL) AS "Calls answered"
FROM Catalog.db.table
WHERE initiationmethod = 'INBOUND' AND queue is not null
GROUP BY queue.name, cast(substring(connectedtosystemtimestamp,1,10) as date)
sql excel amazon-web-services
1个回答
0
投票

这是无效的SQL:

SUM(CASE initiationmethod=’INBOUND’, name IS NOT NULL AND agent IS NOT NULL) AS "Calls answered"

大概是您想要的:

SUM(CASE 
    WHEN initiationmethod = 'INBOUND' 
        AND name IS NOT NULL 
        AND agent IS NOT NULL 
    THEN 1 
    ELSE 0 
END) AS "Calls answered"
© www.soinside.com 2019 - 2024. All rights reserved.