使用SQL语句(100)

  • 主题发起人 主题发起人 Daviswang
  • 开始时间 开始时间
D

Daviswang

Unregistered / Unconfirmed
GUEST, unregistred user!
现有如下Table:rb1 rb2 rb3 rb4 rb5 rb6 bb7 sx1 3 8 15 17 21 13 90053 5 7 10 19 23 13 902012 13 15 22 23 29 13 90295 10 16 19 23 28 13 90745 7 12 14 15 20 13 90784 9 11 20 32 33 13 90845 9 15 21 26 31 13 9117即前六个数为红球排序,后一个为蓝球号码(bb7) 第八列为蓝球13的出现期数,使用SQL Server 语句完成如下统计:按顺序相邻的期数差,求其中最大的一个。她们分别为15 9 45 4 6 33.要求得到如下查询:蓝球的最大间隔45最好能列出15 9 45 4 6 33 在显示45的结果。完成如上查询,给出100分。谢谢!急盼回复。不胜感谢!
 
唉!唉!以前论坛人气旺,孤独求索众人帮。人生若寄风吹灯,行来款款落空忙。咋,没有高手回复呀!急死人罗。
 
参考我的这篇SQL偏差问题http://www.delphibbs.com/keylife/iblog_show.asp?xid=27338
 
select Max(B1.sx - B2.sx) from (select * from table where bb7 = 13 order by sx )B1,(select * from table where bb7 = 13 order by sx)B2 where B1.Rowid = B2.Rowid +1
 
很遗憾。!Rowid 关键字仅仅是SQL SERVER 2005允许。程序运行不了呀!急死人了。运行报警:“服务器: 消息 207,级别 16,状态 3,行 1列名 'Rowid' 无效。服务器: 消息 207,级别 16,状态 1,行 1列名 'Rowid' 无效。”请GodIsWrong,重新指点。不胜感谢!
 
select Max(B1.sx - B2.sx) from (select t1.sx, count(t2.sx) ID from Table t1, Table t2 where t2.sx <= t1.sx and t1.bb7 = 13 and t2.bb7 = 13 group by t1.sx order by t1.sx)B1,(select t1.sx, count(t2.sx) ID from Table t1, Table t2 where t2.sx <= t1.sx and t1.bb7 = 13 and t2.bb7 = 13 group by t1.sx order by t1.sx)B2 where B1.ID = B2.ID +1
 
select Max(B1.sx - B2.sx) from (select t1.sx, count(t2.sx) ID from Table t1, Table t2 where t2.sx <= t1.sx and t1.bb7 = 13 and t2.bb7 = 13 group by t1.sx )B1,(select t1.sx, count(t2.sx) ID from Table t1, Table t2 where t2.sx <= t1.sx and t1.bb7 = 13 and t2.bb7 = 13 group by t1.sx )B2 where B1.ID = B2.ID +1
 
十分感谢。钦佩之至。希望得到高手GodIsWrong 的QQ号。我的是13749319 广柑[:)]
 
后退
顶部