从1个具有不同Where条件的表中获取2个查询的结果

时间:2019-01-17 20:05:23

标签: sql amazon-redshift

我想将2个查询合并为一个。它来自同一张表,但where语句略有不同。

我尝试了Union,Filter,并在select语句中使用了多个select语句。

查询1

Select date, count("speed of answer") as TotalCalls     
From five9_data.calllog     
Where Campaign IN ('FYF', 'SF') 
    and "Campaign Type" IN ('Inbound') 
    and "Time TO Abandon" is null     
Group By date     
Order By date Desc

查询2

Select date, count("Time To Abandon") as AbandonCalls 
From five9_data.calllog 
Where Campaign IN ('FYF', 'SF') 
    and "Campaign Type" IN ('Inbound') 
    and "Time TO Abandon" > '0' 
Group By date 
Order By date Desc

我希望日期,列中包含来自总通话的结果以及来自放弃通话的结果。如果您发现两者的where语句中的第三个条件是最大的不同。

2 个答案:

答案 0 :(得分:1)

我认为您需要条件聚合:

SaveMode.Append

答案 1 :(得分:0)

选择

date,sum((“放弃时间”为null):: int)为TotalCalls,

   sum( ("Time TO Abandon" > 0)::int ) as AbandonCalls

来自Five9_data.calllog

广告系列IN(“ FYF”,“ SF”)和“广告系列类型” IN(“入站”)的位置

按日期分组

按日期排序Desc;