获取最近4个月的百分比SQL Netezza

我有一个简单的查询表

SELECT Call_Date, Phone_Num, Call_Type
FROM IVR_TBL

结果像

CALL_DATE            |Phone_Num       |CALL_TYPE |
---------------------|----------------|----------|
2020-01-30 21:12:0   |0553748547      |Technical |
2020-02-23 21:10:0   |0224643303      |Sales     |
2020-05-01 09:00:0   |0224432454      |Technical |
2020-04-02 09:05:0   |0453652041      |Technical |
2020-03-30 08:59:0   |0934604076      |Sales     |
2020-02-28 21:17:0   |0244794546      |Sales     |
2020-01-23 21:20:0   |0238441865      |Sales     |
2020-05-16 21:18:0   |0552715113      |Sales     |
2020-04-28 21:22:0   |0502132405      |Technical |

我怎么能得到

  • Percentage of Distinct customers calls report (from Phone_Num) within 1 month (Customers who contacted us 1 time during a month) and group them by CALL_TYPE

  • Percentage of Distinct customers calls report (from Phone_Num) within 4 months (Customers who contacted us 1 time during the 4 months ) and group them by CALL_TYPE

1个月的结果仅包含3个字段,如下所示

Month   |Call_Type  |Percentage  |
--------|-----------|------------|
Jan     |Sales      |            |
Feb     |Sales      |            |  
Mar     |Sales      |            |  
Apr     |Sales      |            |  
May     |Sales      |            |  
Jan     |Technical  |            |
Feb     |Technical  |            |  
Mar     |Technical  |            |  
Apr     |Technical  |            |  
May     |Technical  |            |  

另一个表格显示了4个月的结果,其中还包含在1月至4月期间一次致电给我们的客户数量

Month   |Call_Type  |Percentage  |
--------|-----------|------------|
Jan     |Sales      |            |
Jan     |Technical  |            |  
数据集来自2020年初
评论
  • 纠结旳SS
    纠结旳SS 回复

    你好

    下面的查询为您提供每个月的客户数。您可以根据需要进一步过滤掉它。让我知道您是否需要更多帮助。

    SELECT TO_CHAR( DATE Call_Date,'YYYY-MM-DD'), Phone_Num, Call_Type, count(1)
    FROM IVR_TBL where 
    group by TO_CHAR( DATE Call_Date,'YYYY-MM-DD'), Phone_Num, Call_Type