use school
go
set nocount on
--声明变量
declare @s_no char(3),@s_name char(8),@s_class char(5),@s_avg float
--声明游标
declare st_cursor cursor for select student.sno,student.sname,student.class,
avg(score.degree)
from student,score
where student.sno=score.sno
group by student.sno,student.sname,student.class
order by student.class,student.sno
--打开游标
open st_cursor
--提取第一行数据
fetch next from st_cursor into @s_no,@s_name,@s_class,@s_avg
--打印表标题
print'班号 姓名 班号 平均分'
print'----------------------------'
while @@fetch_status=0
begin
--打印一行数据
print @s_no+' '+@s_name+' '+ @s_class+' '+cast(@s_avg as char(5))
--提取下一行数据
fetch next from st_cursor
into @s_no,@s_name,@s_class,@s_avg
end
--关闭游标
close st_cursor
--释放游标
deallocate st_cursor
go
评论1
最新资源