+ -
当前位置:首页 → 问答吧 → SQL SERVER 2008排列组合算法

SQL SERVER 2008排列组合算法

时间:2011-12-02

来源:互联网

我想学习做一个彩票分析软件,排列于组合可以很快生成出来,但是我想生成出来的号码里面包含某些数字不知道怎么做
生成:
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中的某个数字最大遗漏了多少期!怎么查
能解决以上问题者,膜拜,重谢,做了这个软件,我的算法又提升了一步,哈哈

作者: season8862008   发布时间: 2011-12-02

这个用SQL来做太为难了吧。

作者: fredrickhu   发布时间: 2011-12-02

我没看明白

作者: ssp2009   发布时间: 2011-12-02

1.
SQL code
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

作者: qianjin036a   发布时间: 2011-12-02

2.1 不要五连号
SQL code
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)

作者: qianjin036a   发布时间: 2011-12-02

2.2 三连号必定是三对:
SQL code
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.要根据你的历史记录表来对应处理,查是否相同就行.

作者: qianjin036a   发布时间: 2011-12-02