jfelber
10-22-2010, 06:29 AM
I've been stuck for a while now trying to get this moderate query work. I may be going about this wrong as well. Here's the setup:
I have a [Notes] table that contains a nonunique (Number) column and a nonunique (Result) column. I'm looking to create a SELECT statement that will display each distinct (Number) value where the count of the {(Number), (Result)} tuple where Result = 'NA' is > 25.
For the actual purpose of the query, we have an autodialer that calls a number and returns a code depending on the results of the call. We want to ignore numbers that have had an 'NA'(no answer) code returned more than 25 times.
My basic attempts so far have been similar to:
SELECT DISTINCT n1.Number FROM Notes n1
WHERE
(SELECT COUNT(*) FROM Notes n2
WHERE n1.Number = n2.Number and n1.Result = 'NA') > 25
I know this isn't correct, but if it's even the basic right approach, I'm not sure how to relate the DISTINCT n1.Number from the initial select to the Number used in the subquery COUNT.
Any ideas or suggestions would be greatly appreciated. I haven't had to deal much with queries in over half a decade, so I'm a little rusty.
-----
Not sure how to delete this post, but I've found out my own answer. To anyone that was interested:
SELECT Number
FROM Notes
WHERE Result = 'NA'
GROUP BY Number
HAVING COUNT(Result) > 25
I have a [Notes] table that contains a nonunique (Number) column and a nonunique (Result) column. I'm looking to create a SELECT statement that will display each distinct (Number) value where the count of the {(Number), (Result)} tuple where Result = 'NA' is > 25.
For the actual purpose of the query, we have an autodialer that calls a number and returns a code depending on the results of the call. We want to ignore numbers that have had an 'NA'(no answer) code returned more than 25 times.
My basic attempts so far have been similar to:
SELECT DISTINCT n1.Number FROM Notes n1
WHERE
(SELECT COUNT(*) FROM Notes n2
WHERE n1.Number = n2.Number and n1.Result = 'NA') > 25
I know this isn't correct, but if it's even the basic right approach, I'm not sure how to relate the DISTINCT n1.Number from the initial select to the Number used in the subquery COUNT.
Any ideas or suggestions would be greatly appreciated. I haven't had to deal much with queries in over half a decade, so I'm a little rusty.
-----
Not sure how to delete this post, but I've found out my own answer. To anyone that was interested:
SELECT Number
FROM Notes
WHERE Result = 'NA'
GROUP BY Number
HAVING COUNT(Result) > 25