您的位置:自考365 > 复习指导 > 历年试题 > 北大“数据库原理”上机实践题目总结(12)

北大“数据库原理”上机实践题目总结(12)

2007-07-18 14:55   【 】【我要纠错

  declare @WID char(5)

  declare @RID char(5)

  set @MAX_Earning = -65535

  set @NumID = 'XXX'

  set @MAX_NumID = 'XXX'

  declare CurNum cursor for

  select NID

  from Numbers

  open CurNum

  fetch from CurNum into @NumID

  while @@fetch_status = 0

  begin

  set @Earning = 0

  declare CurChip cursor for

  select RRecord.HID as WinID,CRecord.HID as RID

  from RRecord,CRecord

  where RRecord.SerNum = CRecord.SerNum and CRecord.NID = @NumID

  open CurChip

  fetch from CurChip into @WID,@RID

  while @@fetch_status = 0

  begin

  if @WID = @RID

  set @Earning = @Earning + 8

  else

  set @Earning = @Earning - 2

  fetch from CurChip into @WID,@RID

  end

  close CurChip

  DEALLOCATE CurChip

  if @Earning > @MAX_Earning

  begin

  set @MAX_NumID = @NumID

  set @MAX_Earning = @Earning

  end

  print @NumID + CONVERT(Varchar(20),@Earning)

  fetch from CurNum into @NumID

  end

  close CurNum

  DEALLOCATE CurNum

  print '赚钱最多的会员'

  print @MAX_NumID + CONVERT(Varchar(20),@MAX_Earning)

  /*=======================================================*/

  /*马场主赚了多少钱*/

  declare @Cash int

  set @Cash = 0

  declare CurTol cursor for

  select RRecord.HID as WinID,CRecord.HID as RID

  from RRecord,CRecord

  where RRecord.SerNum = CRecord.SerNum

  open CurTol

  fetch from CurTol into @WID,@RID

  while @@fetch_status = 0

  begin

  if @WID = @RID

  set @Cash = @Cash - 8

  else

  set @Cash = @Cash + 2

  fetch from CurTol into @WID,@RID

  end

  close CurTol

  DEALLOCATE CurTol

  print '场主赚了' + CONVERT( VARCHAR(10),@CASH) + '钱'

  drop table CRecord

  drop table RRecord

  drop table Numbers

  drop table Horses

本文转载链接:北大“数据库原理”上机实践题目总结(12)

分享到:
  • 站内搜索
  • 课程搜索
  • 试题搜索

热门搜索:教材 报名 查分 免考 考试计划