Oracle SQL语句 - 识别&统计唯一来电者

时间:2018-03-06 15:03:23

标签: sql oracle telephony

我希望对我们的电话呼叫数据进行一些改进 - 并且要求识别CALLER是否是唯一的 - 如果他们在给定日期(CALL_DATE)多次呼叫 - 它标记为1值,如果只有一次0值。

我是否可以修改此现有语句以反映这一点?

SELECT /*+ PARALLEL (4) */
A.CALL_ID,
A.CALL_DATE,
O.OT_OUTLET_CODE,
A.CALL_TIME,
TO_CHAR(TO_DATE(A.CALL_TIME, 'HH24:MI:SS')+A.TALK_TIME/(24*60*60),'HH24:MI:SS') "CALL_END_TIME",
A.TALK_TIME,
A.RING_TIME,
A.OUTCOME,
CASE WHEN A.TRANSFER_TO = '10000' THEN 1 ELSE 0 END AS "VOICEMAIL"
FROM
    OWBI.ODS_FACT_TIGER_TELEPHONY A,
    OWBI.WHS_DIM_CAL_DATE C,
    OWBI.WHS_DIM_OUTLET O
WHERE
                A.CALL_DATE = C.CD_DAY_DATE
        AND     A.WHS_DIM_OUTLET = O.DIMENSION_KEY
        AND     C.EY_YEAR_CODE IN       ('2019')
        AND     C.EW_WEEK_IN_YEAR IN    ('1')      --  **FILTER ON PREVIOUS BUSINESS WEEK NUMBER**

ORDER BY A.CALL_DATE DESC;

1 个答案:

答案 0 :(得分:0)

您所描述的内容听起来像分析 count(*)函数的工作。

将其添加到SELECT子句中,不要更改任何其他内容:

case when count(*) over (partition by a.call_id, a.call_date) = 1 then 0
     else 1 end as unique_flag