我想学习做一个彩票分析软件,排列于组合可以很快生成出来,但是我想生成出来的号码里面包含某些数字不知道怎么做
生成:
create table #number(T1 tinyint)
declare @T1 tinyint
SET @T1 = 1
WHILE @T1 <= 33
BEGIN
INSERT INTO #number VALUES(@T1)
SET @T1 = @T1 + 1
END
select * from #number a1,#number a2,#number a3,#number a4,#number a5,#number a6
where a1.t1 < a2.t1 and
      a2.t1 < a3.t1 and
      a3.t1 < a4.t1 and
      a4.t1 < a5.t1 and
      a5.t1 < a6.t1
1.然后在这100多万注里有 1,2,3,4,5,6,7,8,9,10里1-3个号码的挑出来,超过4个以上的不显示出来怎么弄?
2.连号数字不需要5连号以上的数字,如1,2,3,4,5,8,最多4连号,并且连号对数不超过2个,如1,2,6,7,8,11
3.怎么计算遗漏值的,我有个历史开奖档,里面有T1,T2,T3,T4,T5,T6分别对应大小顺序排列的开奖记录
  我想算下T1中的某个数字最大遗漏了多少期!怎么查
能解决以上问题者,膜拜,重谢,做了这个软件,我的算法又提升了一步,哈哈

解决方案 »

  1.   

    1.
    select * from #number a1,#number a2,#number a3,#number a4,#number a5,#number a6
    where a1.t1 < a2.t1 and
      a2.t1 < a3.t1 and
      a3.t1 < a4.t1 and
      a4.t1 < a5.t1 and
      a5.t1 < a6.t1 
    and (case when a1.t1<=10 then 1 else 0 end)+
    (case when a2.t1<=10 then 1 else 0 end)+
    (case when a3.t1<=10 then 1 else 0 end)+
    (case when a4.t1<=10 then 1 else 0 end)+
    (case when a5.t1<=10 then 1 else 0 end)+
    (case when a6.t1<=10 then 1 else 0 end) between 1 and 3
      

  2.   

    2.1 不要五连号
    select * from #number a1,#number a2,#number a3,#number a4,#number a5,#number a6
    where a1.t1 < a2.t1 and
      a2.t1 < a3.t1 and
      a3.t1 < a4.t1 and
      a4.t1 < a5.t1 and
      a5.t1 < a6.t1 
    and not(a1.t1=a2.t2-1 and a2.t1=a3.t1-1 and a3.t1=a4.t1-1 and a4.t1=a5.t1-1 or a2.t1=a3.t1-1 and a3.t1=a4.t1-1 and a4.t1=a5.t1-1 and a5.t1=a6.t1-1)
      

  3.   

    2.2 三连号必定是三对:
    select * from #number a1,#number a2,#number a3,#number a4,#number a5,#number a6
    where a1.t1 < a2.t1 and
      a2.t1 < a3.t1 and
      a3.t1 < a4.t1 and
      a4.t1 < a5.t1 and
      a5.t1 < a6.t1 
    and not(a1.t1=a2.t2-1 and a2.t1<>a3.t1-1 and a3.t1=a4.t1-1 and a4.t1<>a5.t1-1 and a5.t1=a6.t1-1)3.要根据你的历史记录表来对应处理,查是否相同就行.
      

  4.   


    -- 1.然后在这100多万注里有 1,2,3,4,5,6,7,8,9,10里1-3个号码的挑出来,超过4个以上的不显示出来怎么弄?with season as
    (select a1.t1 n1, a2.t1 n2, a3.t1 n3, a4.t1 n4, a5.t1 n5, a6.t1 n6
     from #number a1,#number a2,#number a3,#number a4,#number a5,#number a6
     where 
     a1.t1 < a2.t1 and
     a2.t1 < a3.t1 and
     a3.t1 < a4.t1 and
     a4.t1 < a5.t1 and
     a5.t1 < a6.t1)
    select * from season
    where
    (case when n1<=10 then 1 else 0 end+
     case when n2<=10 then 1 else 0 end+
     case when n3<=10 then 1 else 0 end+
     case when n4<=10 then 1 else 0 end+
     case when n5<=10 then 1 else 0 end+
     case when n6<=10 then 1 else 0 end
    )<=3
      

  5.   

    sorry, 是有bug, 修正如下, 感谢晴天指正,-- 1.然后在这100多万注里有 1,2,3,4,5,6,7,8,9,10里1-3个号码的挑出来,超过4个以上的不显示出来怎么弄?with season as
    (select a1.t1 n1, a2.t1 n2, a3.t1 n3, a4.t1 n4, a5.t1 n5, a6.t1 n6
     from #number a1,#number a2,#number a3,#number a4,#number a5,#number a6
     where 
     a1.t1 < a2.t1 and
     a2.t1 < a3.t1 and
     a3.t1 < a4.t1 and
     a4.t1 < a5.t1 and
     a5.t1 < a6.t1)
    select * from season
    where
    (case when n1<=10 then 1 else 0 end+
     case when n2<=10 then 1 else 0 end+
     case when n3<=10 then 1 else 0 end+
     case when n4<=10 then 1 else 0 end+
     case when n5<=10 then 1 else 0 end+
     case when n6<=10 then 1 else 0 end
    ) between 1 and 3
      

  6.   


    --2.连号数字不需要5连号以上的数字,如1,2,3,4,5,8,最多4连号,并且连号对数不超过2个,如1,2,6,7,8,11with season as
    (select a1.t1 n1, a2.t1 n2, a3.t1 n3, a4.t1 n4, a5.t1 n5, a6.t1 n6
     from #number a1,#number a2,#number a3,#number a4,#number a5,#number a6
     where 
     a1.t1 < a2.t1 and
     a2.t1 < a3.t1 and
     a3.t1 < a4.t1 and
     a4.t1 < a5.t1 and
     a5.t1 < a6.t1)
    select * from season
    where
     not((n1+1=n2 and n2+1=n3 and n3+1=n4 and n4+1=n5)  -- 排除5連號,6連號的.
          or(n2+1=n3 and n3+1=n4 and n4+1=n5 and n5+1=n6)
          or(n1+1=n2 and n2+1=n3 and n3+1=n4 and n4+1=n5 and n5+1=n6))--> 以上實現了一半,另一個需確認一下: 1 2 3 4 ... 算2對連號還是3對連號?
      

  7.   


    -- 3.怎么计算遗漏值的,我有个历史开奖档,里面有T1,T2,T3,T4,T5,T6分别对应大小顺序排列的开奖记录
    --   我想算下T1中的某个数字最大遗漏了多少期!怎么查--> 沒有表結構,以下是偽代碼供參考.
    declare @t int
    select @t=[某个数字]with t1 as
    (select row_number() over(order by 期數) rn, [期數]
    from [历史开奖档]
    where (n1=@t or n2=@t or n3=@t or n4=@t or n5=@t or n6=@t)),
    t2 as
    (select b.[期數]-a.[期數] y
     from t1 a
     left join t1 b on a.rn=b.rn-1)
    select max(y) '最大遗漏了期数' from y 
      

  8.   

    算一对4连号,1 2 5 6算两对2连号楼上的答案,看不懂啊,我的表是HISTORY结构是QIHAO[期号],T1,T2,T3,T4,T5,T6对应从小到大排列的开奖历史,你给我写个可以直接复制执行的,然后我慢慢研究
      

  9.   


    期号int 不会重复的如2011141意思就是2011年第141期
    关于连号,只要中间没有断,就算一对连号1234算一对4连号
      

  10.   


    -- 3.怎么计算遗漏值的,我有个历史开奖档,里面有T1,T2,T3,T4,T5,T6分别对应大小顺序排列的开奖记录
    --   我想算下T1中的某个数字最大遗漏了多少期!怎么查--> 沒有表結構,以下是偽代碼供參考.
    declare @t int
    select @t=[某个数字]with t0 as
    (select row_number() over(order by QIHAO) rn, QIHAO,
    T1,T2,T3,T4,T5,T6 from HISTORY),
    t1 as
    (select row_number() over(order by QIHAO) rn2,* from t0 
    where T1=@t or T2=@t or T3=@t or T4=@t or T5=@t or T6=@t),
    t2 as
    (select b.rn-a.rn y
     from t1 a
     left join t1 b on a.rn2=b.rn2-1)
    select max(y) '最大遗漏了期数' from t2