我在Oracle SQL查询中遇到问题。我不知道如何得到这个查询的总和:
select call_type, channel
,count (case when status="no answer" then 1 end else 0) as cnt_no_answer
,count (case when status="answered" then 1 end else 0) as cnt_answer
from app_account.cc_call;
请帮帮我。谢谢!
答案 0 :(得分:2)
再试一次,我编辑它:
SELECT call_type, channel,
sum (CASE WHEN status='no answer' THEN 1 ELSE 0 END) AS cnt_no_answer,
sum (CASE WHEN status='answered' THEN 1 ELSE 0 END) AS cnt_answer
FROM app_account.cc_call
GROUP BY call_type, channel;
答案 1 :(得分:2)
获取已回答且未回答的记录总数而非计数。要获取已应答或未应答的所有记录的数量,请使用count(status)。要获取所有记录的计数,即状态为null的记录,请使用count(*)。字符串需要单引号,而不是双引号。案例陈述需要END。
EDITED(使用的END太多了):
select call_type, channel
, sum(case when status='no answer' then 1 else 0 end) as cnt_no_answer
, sum(case when status='answered' then 1 else 0 end) as cnt_answer
, count(status) as cnt_all_stated
, count(*) as cnt_all_records
from app_account.cc_call
group by call_type, channel;
答案 2 :(得分:1)
检查出来:
SELECT CALL_TYPE,
CHANNEL,
COUNT (CASE WHEN UPPER(STATUS) = UPPER('no answer') THEN 1 ELSE NULL END)
AS CNT_NO_ANSWER,
COUNT (CASE WHEN UPPER(STATUS) = UPPER('answered') THEN 1 ELSE NULL END)
AS CNT_ANSWER
FROM APP_ACCOUNT.CC_CALL
GROUP BY CALL_TYPE, CHANNEL;
答案 3 :(得分:1)
选择call_type,channel
,总和(情况='无答案'然后1其他0结束时的情况)为cnt_no_answer
,总和(情况='回答'然后1,否则0结束时的情况)为cnt_answer
,将(状态)计为cnt_all_stated
,将(*)计为cnt_all_records
按call_type分组,频道;
为什么usind结束两次
答案 4 :(得分:1)
SELECT Call_type, Channel
,COUNT(CASE WHEN status="no answer" then 1 else 0 end ) as Cnt_no_answer
,COUNT(CASE WHEN status="answered" then 1 else 0 end ) as Cnt_answer
from App_account.cc_call
GROUP BY call_type,channel;
我认为表减速有一些错误。请求给表结构。你想要SUM和你在那里计算我不认为这是错误但缺乏概述。请提供更多详情。