先查询每一条记录,向前查询365天前的电话记录,如果有,计数一次,得到每一条记录前365天的电话记录次数,
再过滤次数大于3的记录.(mysql)
select b.电话,
sum((select count(时间) from a where DATEDIFF(date_format(b.`时间`,'%Y-%m-%d'),date_format(时间,'%Y-%m-%d'))>0 and `电话`=b.`电话` GROUP BY 电话))as 次数
from a as b
group by b.电话
having 次数>=3