Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 sql qustion about query

Author  Topic 

yuri1992
Starting Member

2 Posts

Posted - 2009-04-26 : 09:20:26
hello to all , i have problem ,
my sql table called Kings
and its look like this
ID Game1 Game2 Game3 Game4 Game5 Game6 Game 7 Date Username
1 213 222 323 232 522 212 122 3.4.09 user1
2 214 212 325 432 262 222 292 3.4.09 user55
3 253 222 523 832 224 232 228 3.4.09 user77
4 273 212 723 233 222 225 272 3.4.09 user5
5 223 272 363 123 122 262 622 3.4.09 user2

I need to pull from the table ten numbers that appeared most in
columns game1 game2 game3 game4 game5 game6 game7 and show them in Sort order
how i do this ?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-04-26 : 09:22:39
What is your expected output from above posted sample data?



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

yuri1992
Starting Member

2 Posts

Posted - 2009-04-26 : 09:55:42
the output will be
1)222 - show 4 time
2)212 - show 2 time
and Onwards
Go to Top of Page

singularity
Posting Yak Master

153 Posts

Posted - 2009-04-26 : 12:53:28
select top 10 game
from
(select game, count(*) as cnt
from
(select game1 as game
from kings
union all
select game2 as game
from kings
union all
select game3 as game
from kings
union all
select game4 as game
from kings
union all
select game5 as game
from kings
union all
select game6 as game
from kings
union all
select game7 as game
from kings) a
group by game) b
order by cnt desc
Go to Top of Page
   

- Advertisement -