Wow, your column names scream bad design!
You could re-write your where clause like this by the by
Code:
WHERE num1 IN (number1, number2, ... , numberN)
As you have found, with the design you have implemented, even the simplest queries become a heck of a lot more complex and inefficient.
If you had chosen a table structure such as
LotteryResults(
draw_date,
number)
Then your query would be as simple as pie
Code:
DECLARE @LotteryResultstable (draw_date datetime, number int)
INSERT INTO @LotteryResults (draw_date, number)
SELECT '20080101', 1
UNION SELECT '20080101', 13
UNION SELECT '20080101', 27
UNION SELECT '20080101', 31
UNION SELECT '20080101', 38
UNION SELECT '20080101', 41
UNION SELECT '20080107', 7
UNION SELECT '20080107', 9
UNION SELECT '20080107', 13
UNION SELECT '20080107', 17
UNION SELECT '20080107', 33
UNION SELECT '20080107', 39
UNION SELECT '20080114', 2
UNION SELECT '20080114', 9
UNION SELECT '20080114', 13
UNION SELECT '20080114', 19
UNION SELECT '20080114', 20
UNION SELECT '20080114', 46
SELECT TOP 2
number
, Count(*) As [frequency]
FROM @LotteryResults
GROUP
BY number
ORDER
BY Count(*) DESC
Code:
number frequency
----------- -----------
13 3
9 2
(2 row(s) affected)
I urge that you go back and re-think your design
