select t1.callid, t1.segstart, t1.calling_pty
from MyTable t1
inner join MyTable t2 on t1.calling_pty = t2.calling_pty
and t1.segstart < t2.segstart
where datediff(mi, t1.segstart, t2.segstart) <= 5
Please note that since it DATEDIFFcounts the number of date boundaries that overlap, it can be somewhat approximate when counting minutes. For better accuracy you can use
where datediff(s, t1.segstart, t2.segstart) <= 300 --this looks at difference in seconds, so much nmore accurate
source
share