0

I need to find out a list of mobiles who have been contacted thrice over a period of two days using columns like mobile and call_time?

From my understanding, I have tried using below code, by using self-join it will match similar mobile numbers and I need to find out if a mobile repeated thrice or more but I also need to find out difference between the maximum and minimum call time for a particular customer to see if it is less than two days. Do let me know how to implement that logic:

select c1.mobile
from call_Records c1, call_Records c2
where c1.mobile=c2.mobile and max(call_time)-min(call_time)<=2

I would want data to be like:

Customer Mobile

XXXXX0001

XXXXX0002

XXXXX0003

4

1 回答 1

0

此查询应为您提供所需的结果。它基于在原始呼叫的 2 天内被呼叫的同一台手机进行自加入,然后计算行数,仅返回 2 天内呼叫 3 次或更多的行。

SELECT c1.mobile, c1.call_time
FROM call_Records c1
JOIN call_Records c2 ON c2.mobile = c1.mobile
WHERE c2.call_time >= c1.call_time - INTERVAL 2 DAY AND c2.call_time < c1.call_time
GROUP BY c1.mobile, c1.call_time
HAVING COUNT(*) >= 3
于 2019-04-01T05:35:06.027 回答