统计应用中的SQL Server 查询语句,两题,各100分(100)

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

Daviswang

Unregistered / Unconfirmed
GUEST, unregistred user!
问题1:SQL查询语句 两个命题:如下表: rb1 rb2 rb3 rb4 rb5 rb6 bb7 xs 。。。 。。。 4 14 15 21 23 30 7 9132 5 9 13 18 20 32 1 9133 3 5 12 15 28 33 6 9134 1 3 14 19 30 33 16 9135 1 4 14 22 30 33 1 9136#######################################################如何使用SQL语句查询开奖号码红球中含有“14”和“30”的所有记录(筛选法不计顺序)?问题2: 在双色球蓝球(1~16号 )统计中出现频率统计,举例子如2009年蓝色球1号按顺序出现了12期(xs列),现将每相邻的期数相减后的累加和,再除以相邻组(即出现期数-1),具体如下:5 11 14 17 18 28 1 90151 2 3 15 30 33 1 903111 14 16 18 26 30 1 90443 4 6 23 30 32 1 90453 7 11 15 17 31 1 90481 11 20 31 32 33 1 90911 11 20 31 32 33 1 90935 6 7 14 25 28 1 91097 14 16 27 29 32 1 91225 8 15 16 26 32 1 91285 9 13 18 20 32 1 91331 4 14 22 30 33 1 9136相邻两期的累加和计算:(9031-9015)+(9044-9031)+(9045-9044)+(9048-9045)+(9091-9048)+(9093-9091)+(9109-9093)+(9122-9109)+(9128-9122)+(9133-9128)+(9136-9133)=121相邻的组数(即出现的期数-1)=11统计频率=121/11=11 大约每11期后出现一次。请提供SQL查询语句。以上,每解决一道,赠分100分。谢谢
 
answer q1:select * from t1 where (rb1=14 orb rb2=14 orb rb3=14 orb rb4=14 orb rb5=14 orb rb6=14)and(rb1=30 orb rb2=30 orb rb3=30 orb rb4=30 orb rb5=30 orb rb6=30)answer q2:create table t1(xs int,bb7 int)insert into t1 values(911,1)insert into t1 values(913,1)select identity(int,1,1)as id, * into #t from t1select (d.bb - c.aa)/(d.ff+c.ee) from(select sum(xs) as aa,count(*) as ee from (select xs from #t where bb7 = 1 and id %2 =1 ) as a) as c,(select sum(xs) as bb,count(*) as ff from (select xs from #t where bb7 = 1 and id %2 =0 ) as b) as d最后是应得 不叫赠,BYL
 
create table ab(xs int,bb7 int)insert into ab values(911,1)insert into ab values(913,1)select identity(int,1,1)as id, * into #t from abselect (d.bb - c.aa)/(d.ff+c.ee) from(select sum(xs) as aa,count(*) as ee from (select xs from #t where bb7 = 1 and id %2 =1 ) as a) as c,(select sum(xs) as bb,count(*) as ff from (select xs from #t where bb7 = 1 and id %2 =0 ) as b) as d where xs>'9001'执行如下:出错。帮忙修改,加分100分。再次感谢!服务器: 消息 213,级别 16,状态 4,行 1插入错误: 列名或所提供值的数目与表定义不匹配。服务器: 消息 213,级别 16,状态 1,行 1插入错误: 列名或所提供值的数目与表定义不匹配。服务器: 消息 207,级别 16,状态 1,行 7列名 'xs' 无效。
 
要求如下: (1)熟悉JAVA或者.net或者IBM LOUTS开发环境建设 OA系统,(2)另外能够做基于.net的开发平台处理HR,ASM,OA 及ERP等 (3)有实际工作经验5年以上。待遇:技术主管:年薪10万-15万。工程开发人员年薪5万元。可安排宿舍及配车。望有成功项目实施经验的开发与管理人员积极应聘。 电话:020-88270969 传真:020-87011505 广州博阳计算机科技有限公司 联系人:孙先生
 
问题二补充,如下sql语句select min(t1.xs-t2.xs) from t t1 join t t2 on t1.xs>t2.xs group by t1.xs得到下列结果表(9031-9015)(9044-9031)(9045-9044)(9048-9045)(9091-9048)(9093-9091)(9109-9093)(9122-9109)(9128-9122)(9133-9128)(9136-9133)
 
问题一解答select * from t1 where (rb1=14 or rb2=14 or rb3=14 or rb4=14 or rb5=14 or rb6=14) and (rb1=30 or rb2=30 or rb3=30 or rb4=30 or rb5=30 or rb6=30)优化方案:根据红球rb1到rb6数值,一般是由小到大出现的规律,判断是否有30时,可以先从rb6开始判断,即优化为select * from t1 where (rb1=14 or rb2=14 or rb3=14 or rb4=14 or rb5=14 or rb6=14) and (rb6=30 or rb5=30 or rb4=30 or rb3=30 or rb2=30 or rb1=30)问题二解答(9031-9015)+(9044-9031)+(9045-9044)+(9048-9045)+(9091-9048)+(9093-9091)+(9109-9093)+(9122-9109)+(9128-9122)+(9133-9128)+(9136-9133),展开以后其实等于9136-9015=121,即最大值减去最小值,所以解答为select (max(xs)-min(xs))/(count(*)-1) from t1
 
谢谢相助!liuyashoa 的解答精准简练,调试一次通过,一并解决了其他问题,收益颇多。感谢大富翁论坛及诸位大虾。[blue]Davis Wang 13749319[:(!][/blue]
 
后退
顶部