福彩22选5缩水SQL算法

http://www.chenjiliang.com/Article/View.aspx?ArticleID=2437

/**************************************
* 软件名称: 福彩22选5缩水软件
* 开 发 者: tohen
* 开发日期: 2007-05-10
* 备 注:
1.其算法适合所有的乐透型彩票
2.缩水条件可拓展
**************************************
*/

/* 创建基本表
create table T1(R1 varchar(10))
create table T2(R2 varchar(10))
create table T3(R3 varchar(10))
create table T4(R4 varchar(10))
create table T5(R5 varchar(10))
delete from T1
delete from T2
delete from T3
delete from T4
delete from T5
*/

/*** 组合数据 ***/
--R1

declare @i int
set @i=1
A:
begin
insert into T1 select right('0'+Cast(@i as varchar(10)),2)
end
set @i=@i+1
if @i <=18 goto A
select * from T1
GO

--R2

declare @i int
set @i=2
A:
begin
insert into T2 select right('0'+Cast(@i as varchar(10)),2)
end
set @i=@i+1
if @i <=19 goto A
select * from T2
GO

--R3

declare @i int
set @i=3
A:
begin
insert into T3 select right('0'+Cast(@i as varchar(10)),2)
end
set @i=@i+1
if @i <=20 goto A
select * from T3
GO

--R4

declare @i int
set @i=4
A:
begin
insert into T4 select right('0'+Cast(@i as varchar(10)),2)
end
set @i=@i+1
if @i <=21 goto A
select * from T4
GO

--R5

declare @i int
set @i=5
A:
begin
insert into T5 select right('0'+Cast(@i as varchar(10)),2)
end
set @i=@i+1
if @i <=22 goto A
select * from T5
GO

/*** 整合表(全部组合) ***/
select * into T from T1,T2,T3,T4,T5
where
R1
<R2 and R1<R3 and R1<R4 and R1<R5 and
R2
<R3 and R2<R4 and R2<R5 and
R3
<R4 and R3<R5 and R4<R5


/*** 缩水 ***/
select * from T where
--首号: [02,X)

R1
>='02'
--尾号: (X,20]

and R5<='20'
--奇数: 2个

and (R1%2 + R2%2 + R3%2 + R4%2 + R5%2)=2
--和值: 40

and (Cast(R1 as int) + Cast(R2 as int) + Cast(R3 as int) + Cast(R4 as int) + Cast(R5 as int))=40
--连号: 2个

and (Case Cast(R2 as int)-Cast(R1 as int) when 1 then 1 else 0 end)+
(
Case Cast(R3 as int)-Cast(R2 as int) when 1 then 1 else 0 end)+
(
Case Cast(R4 as int)-Cast(R3 as int) when 1 then 1 else 0 end)+
(
Case Cast(R5 as int)-Cast(R4 as int) when 1 then 1 else 0 end) = 2
--跨度: 10

and Cast(R5 as int)-Cast(R1 as int)=10
--重号: 2个 (假设上期开奖号为:01,02,03,04,05)

and (Case when R1 in ('01','02','03','04','05') then 1 else 0 end)+
(
Case when R2 in ('01','02','03','04','05') then 1 else 0 end)+
(
Case when R3 in ('01','02','03','04','05') then 1 else 0 end)+
(
Case when R4 in ('01','02','03','04','05') then 1 else 0 end)+
(
Case when R5 in ('01','02','03','04','05') then 1 else 0 end)=2
--AC值: 9

and (select count(*) from
(
select right('0'+Cast(Cast(R5 as int)-Cast(R4 as int) as varchar(10)),2) as a union
select right('0'+Cast(Cast(R5 as int)-Cast(R3 as int) as varchar(10)),2) union
select right('0'+Cast(Cast(R5 as int)-Cast(R2 as int) as varchar(10)),2) union
select right('0'+Cast(Cast(R5 as int)-Cast(R1 as int) as varchar(10)),2) union
select right('0'+Cast(Cast(R4 as int)-Cast(R3 as int) as varchar(10)),2) union
select right('0'+Cast(Cast(R4 as int)-Cast(R2 as int) as varchar(10)),2) union
select right('0'+Cast(Cast(R4 as int)-Cast(R1 as int) as varchar(10)),2) union
select right('0'+Cast(Cast(R3 as int)-Cast(R2 as int) as varchar(10)),2) union
select right('0'+Cast(Cast(R3 as int)-Cast(R1 as int) as varchar(10)),2) union
select right('0'+Cast(Cast(R2 as int)-Cast(R1 as int) as varchar(10)),2)) A) = 9

posted @ 2011-07-05 16:39  董雨  阅读(314)  评论(0编辑  收藏  举报