自考人的网上家园

当前位置:首页  > 复习指导  > 历年试题  > 正文

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

2007/07/18  来源:    字体:  打印

  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

自考整专业报考 自考会展管理专业招生开始