WayneGretzky
Programmer
This query still produces results that are wrong. It should never return any crc unless it = 'error' and it does.
Second, it should only return results where there are more than 2 records with the same phone number for those records where the crc = 'error'
select calldatetime, crc, projname, phonenum from dbo.history h
WHERE ProjName IN ('sss' , 'mmm')
AND ((EXISTS(SELECT Phonenum FROM history hh WHERE h.CRC = 'ERROR'AND hh.phonenum = h.phonenum GROUP BY hh.Phonenum HAVING COUNT(hh.Phonenum) > 2 )))
AND (CallDateTime between dateadd(mi, -130, GetDate()) and Getdate())
AND PhoneNum LIKE '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
This query also does the same thing:
select h.calldatetime, h.crc, h.projname, h.phonenum from dbo.history h
WHERE ProjName IN ('sss' , 'mmm')
AND (SELECT Count(*) FROM history WHERE CRC = 'ERROR' and phonenum = h.phonenum HAVING Count(*) > 2) > 2
AND (CallDateTime between dateadd(mi, -130, GetDate()) and Getdate())
AND PhoneNum LIKE '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
Output looks like this which is not correct:
2006-01-05 16:25:19.000 OK sss 8668762739
2006-01-05 16:47:22.000 error mmm 8668762739
2006-01-05 16:53:23.000 OK mmm 8668762739
2006-01-05 17:15:26.000 AMM sss 8668762739
I should not be seeing OK or AMM, and I should be seeing more than one error for the same phone number
Second, it should only return results where there are more than 2 records with the same phone number for those records where the crc = 'error'
select calldatetime, crc, projname, phonenum from dbo.history h
WHERE ProjName IN ('sss' , 'mmm')
AND ((EXISTS(SELECT Phonenum FROM history hh WHERE h.CRC = 'ERROR'AND hh.phonenum = h.phonenum GROUP BY hh.Phonenum HAVING COUNT(hh.Phonenum) > 2 )))
AND (CallDateTime between dateadd(mi, -130, GetDate()) and Getdate())
AND PhoneNum LIKE '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
This query also does the same thing:
select h.calldatetime, h.crc, h.projname, h.phonenum from dbo.history h
WHERE ProjName IN ('sss' , 'mmm')
AND (SELECT Count(*) FROM history WHERE CRC = 'ERROR' and phonenum = h.phonenum HAVING Count(*) > 2) > 2
AND (CallDateTime between dateadd(mi, -130, GetDate()) and Getdate())
AND PhoneNum LIKE '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
Output looks like this which is not correct:
2006-01-05 16:25:19.000 OK sss 8668762739
2006-01-05 16:47:22.000 error mmm 8668762739
2006-01-05 16:53:23.000 OK mmm 8668762739
2006-01-05 17:15:26.000 AMM sss 8668762739
I should not be seeing OK or AMM, and I should be seeing more than one error for the same phone number