| | |
Just for fun Lotto SQL
Please support our MS SQL advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2006
Posts: 1
Reputation:
Solved Threads: 0
The data table looks like this
date num1 num2 num3 num4 num5 num6
1/1/06 1 45 32 21 15 48
SQL script 1 should be able to do the following
show the Top 3 number pairs
another words if the pair 45 and 15 shows up 98 times and 32 and 12 shows up 3 times
then I want to have 45 and 15 show as one of the top 3 number pairs
I know this is a difficult one
So that being said see if I can re-explain it here
I have say two dates
1/1/2006 and 1/2/2006
on the first date I have six numbers being
1,24,45,35,47,14
and the second date I have
24,35,9,15,46,17
Now I can if it is needed to re do the data structure to reflect it like this
date num
1/1/2006 1
1/1/2006 24
1/1/2006 45
1/1/2006 35
1/1/2006 47
1/1/2006 14
1/2/2006 24
1/2/2006 35
1/2/2006 9
1/2/2006 15
1/2/2006 46
1/2/2006 17
Now somehow I am not sure how but I need to take the six numbers from each date and compare them with every other date.
so another words from date one take 1 and 24 and see if that combo matches other dates then go to 1 and 45 and do the same and so on.
date num1 num2 num3 num4 num5 num6
1/1/06 1 45 32 21 15 48
SQL script 1 should be able to do the following
show the Top 3 number pairs
another words if the pair 45 and 15 shows up 98 times and 32 and 12 shows up 3 times
then I want to have 45 and 15 show as one of the top 3 number pairs
I know this is a difficult one
So that being said see if I can re-explain it here
I have say two dates
1/1/2006 and 1/2/2006
on the first date I have six numbers being
1,24,45,35,47,14
and the second date I have
24,35,9,15,46,17
Now I can if it is needed to re do the data structure to reflect it like this
date num
1/1/2006 1
1/1/2006 24
1/1/2006 45
1/1/2006 35
1/1/2006 47
1/1/2006 14
1/2/2006 24
1/2/2006 35
1/2/2006 9
1/2/2006 15
1/2/2006 46
1/2/2006 17
Now somehow I am not sure how but I need to take the six numbers from each date and compare them with every other date.
so another words from date one take 1 and 24 and see if that combo matches other dates then go to 1 and 45 and do the same and so on.
•
•
Join Date: Sep 2006
Posts: 44
Reputation:
Solved Threads: 3
My approach would be something like the following, assuming the second data structure. (It's untested)
select top 3 d1.num num1, d2.num num2
from data d1 inner join data d2 on (d1.date=d2.date) and (d1.num<d2.num)
group by d1.num, d2.num
having count(distinct d1.date)>1
order by count(*)
select top 3 d1.num num1, d2.num num2
from data d1 inner join data d2 on (d1.date=d2.date) and (d1.num<d2.num)
group by d1.num, d2.num
having count(distinct d1.date)>1
order by count(*)
Last edited by MCP; Dec 3rd, 2006 at 11:04 pm. Reason: changed to more efficient query
•
•
Join Date: Sep 2006
Posts: 44
Reputation:
Solved Threads: 3
•
•
•
•
actually, no need for the distinct count.. :
select top 3 d1.num num1, d2.num num2
from data d1 inner join data d2 on (d1.date=d2.date) and (d1.num<d2.num)
group by d1.num, d2.num
having count(*)>1
order by count(*)

select top 3 d1.num num1, d2.num num2
from data d1 inner join data d2 on (d1.date=d2.date) and (d1.num<d2.num)
group by d1.num, d2.num
having count(*)>1
order by count(*) desc
![]() |
Similar Threads
- HOWTO: Share an SQL Connection between multiple forms within the same project (C#)
- PHP, ASP, ColdFusion, what's your fav? (IT Professionals' Lounge)
- using PL\SQL to drop PK from table (Oracle)
- SQL Server vs MYSQL vs MSQL (i'm stopping now) (MS SQL)
Other Threads in the MS SQL Forum
- Previous Thread: Need SQL Topology Advice
- Next Thread: Importing data from txt file
| Thread Tools | Search this Thread |





