用存储过程计算彩票中的遗漏期数

supermask2004 2009-10-02 04:38:57
小弟是一个彩票爱好者,用SqlServer建了个数据库,有一个表为history,里面有num,r1,r2,r3,r4,r5,r6代表期数和六个红球字段。

小弟还想建一个表:遗漏表yilou,字段也为num,y1,y2,y3,y4,y5,y6代表期数和每个红球的遗漏期数。

例如:下面是几期的数据
num r1 r2 r3 r4 r5 r6

9001 4 21 23 24 30 31
9002 10 14 17 25 29 33
9003 2 3 6 15 25 30
9004 3 11 13 17 28 31
9005 1 3 8 15 17 21
9006 6 12 18 20 26 33
9007 1 5 12 23 25 26
9008 4 15 16 22 32 33
9009 8 15 21 30 31 33

9009期中的8,15,21,30,31,33上次出现分别在005期,008期,005期,003期,004期,008期
则yilou表中009期的数据为:

num y1 y2 y3 y4 y5 y6
9009 3 0 3 5 4 0

我想建个存储过程,自动利用history中的数据建立yilou表,各位帮帮忙啦!

...全文
160 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
appleller 2009-10-06
  • 打赏
  • 举报
回复
这种软件网上很多的,祝你中奖!! 怎么没有蓝球号码呢?
fanzhouqi 2009-10-02
  • 打赏
  • 举报
回复

--> 测试数据: @T1
declare @T1 table (num int,r1 int,r2 int,r3 int,r4 int,r5 int,r6 int)
insert into @T1
select 9001,4,21,23,24,30,31 union all
select 9002,10,14,17,25,29,33 union all
select 9003,2,3,6,15,25,30 union all
select 9004,3,11,13,17,28,31 union all
select 9005,1,3,8,15,17,21 union all
select 9006,6,12,18,20,26,33 union all
select 9007,1,5,12,23,25,26 union all
select 9008,4,15,16,22,32,33 union all
select 9009,8,15,21,30,31,33

declare @t2 table(num int ,value varchar(100))
insert into @t2
select num, rtrim(r1)+','+rtrim(r2)+','+rtrim(r3)+','+rtrim(r4)+','+rtrim(r5)+','+rtrim(r6)
from @t1
order by num desc

select * from @t2
select num
,r1 = (select top 1 a.num-1-num from @t2 where a.num >num and charindex(','+rtrim(r1)+',',','+value+',')>0 )
,r2 = (select top 1 a.num-1-num from @t2 where a.num >num and charindex(','+rtrim(r2)+',',','+value+',')>0)
,r3 = (select top 1 a.num-1-num from @t2 where a.num >num and charindex(','+rtrim(r3)+',',','+value+',')>0)
,r4 = (select top 1 a.num-1-num from @t2 where a.num >num and charindex(','+rtrim(r4)+',',','+value+',')>0)
,r5 = (select top 1 a.num-1-num from @t2 where a.num >num and charindex(','+rtrim(r5)+',',','+value+',')>0)
,r6 = (select top 1 a.num-1-num from @t2 where a.num >num and charindex(','+rtrim(r6)+',',','+value+',')>0)
from @T1 a

num r1 r2 r3 r4 r5 r6
----------- ----------- ----------- ----------- ----------- ----------- -----------
9001 NULL NULL NULL NULL NULL NULL
9002 NULL NULL NULL NULL NULL NULL
9003 NULL NULL NULL NULL 0 1
9004 0 NULL NULL 1 NULL 2
9005 NULL 0 NULL 1 0 3
9006 2 NULL NULL NULL NULL 3
9007 1 NULL 0 5 3 0
9008 6 2 NULL NULL NULL 1
9009 3 0 3 5 4 0

(所影响的行数为 9 行)
supermask2004 2009-10-02
  • 打赏
  • 举报
回复
小弟新来的啊,没什么分啊 如果真中了500w,花钱买分,大大地送
luoyoumou 2009-10-02
  • 打赏
  • 举报
回复
--楼主:比起你中彩票500W来说,这分也忒少了吧?
luoyoumou 2009-10-02
  • 打赏
  • 举报
回复
--楼主:这分也忒少了吧?
supermask2004 2009-10-02
  • 打赏
  • 举报
回复
是找到离他最近的那一个,虽然001中有31,但是004中的31离009中的21最近,呵呵
rucypli 2009-10-02
  • 打赏
  • 举报
回复
31为什么不是001期
rucypli 2009-10-02
  • 打赏
  • 举报
回复
34为什么不是001期

27,580

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧