扫描当前时间到前两小时的话单数据。扫描范围内的数据,满足以下规则,即认为异常。 1)、时间范围内连续拨打同一号码监控 在扫描时间范围内,同一个国际被叫号码连续拨打5(可自行配置)次以上。 2)、时间范围内单次拨打电话通话时间过长监控 在扫描时间范围内,国际拨打的一通电话通话时长超过15分钟(可自行配置)分钟以上。 3)、时间范围内拨打同一个号码次数监控 在扫描时间范围内,同一个被叫国际号码总共被拨打的次数5次(可自行配置)以上。 4)、时间范围内拨打国际长途次数监控 在扫描时间范围内,号码总共拨打国际长途的次数10次(可自行配置)以上。异常信息也要显示,mysql实现
时间: 2024-03-19 12:42:47 浏览: 159
一款使用 Python 编写的图像内表格数据提取工具,可以高效识别 PDF 、扫描件、照片、截图内的表格数据并转Excel文件
5星 · 资源好评率100%
好的,以下是一个可以实现话单数据扫描和异常监控的MySQL查询语句,同时返回异常信息:
```
SELECT
caller_number,
called_number,
call_start_time,
call_end_time,
call_duration,
CASE
WHEN (caller_number, called_number) IN (
SELECT caller_number, called_number
FROM (
SELECT caller_number, called_number, call_start_time,
IF(called_number=@prev_called_number, @cnt:=@cnt+1, @cnt:=1) AS cnt,
@prev_called_number:=called_number
FROM call_records, (SELECT @prev_called_number:=NULL, @cnt:=1) AS vars
WHERE call_start_time >= DATE_SUB(NOW(), INTERVAL 2 HOUR)
AND caller_number NOT LIKE '0%'
ORDER BY called_number, call_start_time
) AS t
WHERE cnt >= 5
) THEN '连续拨打同一号码监控'
WHEN call_duration >= 900 THEN '单次拨打电话通话时间过长监控'
WHEN called_number IN (
SELECT called_number
FROM call_records
WHERE call_start_time >= DATE_SUB(NOW(), INTERVAL 2 HOUR)
AND caller_number NOT LIKE '0%'
GROUP BY called_number
HAVING COUNT(DISTINCT caller_number) >= 5
) THEN '拨打同一个号码次数监控'
WHEN caller_number NOT LIKE '0%' AND LENGTH(caller_number) > 5 AND LENGTH(caller_number) < 16 AND LENGTH(called_number) > 5 AND LENGTH(called_number) < 16
AND (SELECT COUNT(*) FROM call_records WHERE caller_number=cr.caller_number AND called_number=cr.called_number AND call_start_time >= DATE_SUB(NOW(), INTERVAL 2 HOUR)) >= 10 THEN '拨打国际长途次数监控'
ELSE '' END AS exception_rule
FROM call_records AS cr
WHERE call_start_time >= DATE_SUB(NOW(), INTERVAL 2 HOUR)
AND (
(caller_number, called_number) IN (
SELECT caller_number, called_number
FROM (
SELECT caller_number, called_number, call_start_time,
IF(called_number=@prev_called_number, @cnt:=@cnt+1, @cnt:=1) AS cnt,
@prev_called_number:=called_number
FROM call_records, (SELECT @prev_called_number:=NULL, @cnt:=1) AS vars
WHERE call_start_time >= DATE_SUB(NOW(), INTERVAL 2 HOUR)
AND caller_number NOT LIKE '0%'
ORDER BY called_number, call_start_time
) AS t
WHERE cnt >= 5
)
OR
(call_duration >= 900)
OR
(called_number IN (
SELECT called_number
FROM call_records
WHERE call_start_time >= DATE_SUB(NOW(), INTERVAL 2 HOUR)
AND caller_number NOT LIKE '0%'
GROUP BY called_number
HAVING COUNT(DISTINCT caller_number) >= 5
))
OR
(caller_number NOT LIKE '0%' AND LENGTH(caller_number) > 5 AND LENGTH(caller_number) < 16 AND LENGTH(called_number) > 5 AND LENGTH(called_number) < 16
AND (SELECT COUNT(*) FROM call_records WHERE caller_number=cr.caller_number AND called_number=cr.called_number AND call_start_time >= DATE_SUB(NOW(), INTERVAL 2 HOUR)) >= 10)
)
```
这个查询语句会返回扫描时间范围内满足监控规则的通话记录,并且在每条记录的最后添加一个名为`exception_rule`的字段,表示该记录触发的异常规则。如果一条记录没有触发任何规则,则`exception_rule`字段的值为空字符串。
你可以根据实际需要对查询语句进行修改和优化。
阅读全文