我想做一个关于彩票3D的统计程序,无非就是统计每个数字的出现次数,用的ACCESS数据库,字段分别为:0,1,2,3,4,5,6,7,8,9,字段类型为BOOL型的,比如:如果这期开奖号码为123,那么1,2,3这三个字段即为True.
我想通过统计每个字段出现的次数,然后对这些字段进行排序,再将出现次数多的前三个显示出来,后三个显示出来,中间的四个也显示出来。各位能不能帮我看看,具体应该如何写算法呀?!!谢谢!!

解决方案 »

  1.   

    create table test(D0 int,D1 int,D2 int,D3 int,D4 int,D5 int,D6 int,D7 int,D8 int,D9 int)
    insert into test select 0,1,1,1,0,0,0,0,0,0
    insert into test select 0,1,1,1,0,0,0,0,0,0
    insert into test select 0,1,1,1,0,0,0,0,0,0
    insert into test select 0,1,1,1,0,0,0,0,0,0
    insert into test select 0,1,1,1,0,0,0,0,0,0
    insert into test select 0,1,1,1,0,0,0,0,0,0
    insert into test select 0,1,1,1,0,0,0,0,0,0
    insert into test select 0,1,1,1,0,0,0,0,0,0
    insert into test select 0,1,1,1,0,0,0,0,0,0
    insert into test select 0,1,1,1,0,0,0,0,0,0
    declare @temp table(myname varchar(2),myvalue int)
    insert into @temp select '0',Sum(D0) from test
    insert into @temp select '1',Sum(D1) from test
    insert into @temp select '2',Sum(D2) from test
    insert into @temp select '3',Sum(D3) from test
    insert into @temp select '4',Sum(D4) from test
    insert into @temp select '5',Sum(D5) from test
    insert into @temp select '6',Sum(D6) from test
    insert into @temp select '7',Sum(D7) from test
    insert into @temp select '8',Sum(D8) from test
    insert into @temp select '9',Sum(D9) from testdeclare @temp2 table(myname varchar(2),myvalue int)
    insert into @temp2 select top 3 myname,myvalue
    from @temp 
    order by myvalue desc
    insert into @temp2
    select myname,myvalue
    from @temp
    where (myname not in(select top 3 myname from @temp order by myvalue desc)) and  (myname not in(select top 3 myname from @temp order by myvalue asc)) 
    insert into @temp2
    select top 3 myname,myvalue
    from @temp 
    order by myvalue ascselect * from @temp2