在这个墙上敲我的头:
SELECT
vicidial_closer_log.CAMPAIGN_I,
vicidial_closer_log.USER_GROUP,
vicidial_closer_log.LEAD_ID,
SUM(IF(PHONE_CODE = '1', 1,0)) AS 'Call_Count',
SUM(IF(STATUS = 'DROP', 1, 0)) AS 'DROPS',
SUM(IF(STATUS = 'AFTHRS',1,0)) AS 'After Hours'
FROM
vicidial_closer_log
group by vicidial_closer_log.CAMPAIGN_I
;
我需要计算掉落率,基本上将掉落分为通话数。有关如何实现这一目标的任何想法?
答案 0 :(得分:0)
做分工:
SELECT vcl.CAMPAIGN_I, vcl.USER_GROUP, vcl.LEAD_ID,
SUM(PHONE_CODE = '1') AS Call_Count,
SUM(STATUS = 'DROP') AS DROPS,
SUM(STATUS = 'AFTHRS') AS AfterHours,
(SUM(STATUS = 'DROP') / NULLIF(SUM(PHONE_CODE = '1'), 0)) AS DropRate
FROM vicidial_closer_log vcl
GROUP BY vcl.CAMPAIGN_I;
注意:
vcl
)使查询更易于编写和阅读。if()
来计算;你可以使用hte boolean expression。NULLIF()
处理除零。