--8.在教学管理数据库中,创建用户定义函数C_MAX,根据输入的课程名称,输出该门课程最高分数的同学学号。
use jwt
go
if exists (select * from sysobjects where name='C_MAX'and type='FN')
drop function C_MAX
go
create function C_MAX (@C_NAME nchar(8))
returns nchar(10)
as
begin
declare @S_SNO nchar(10)
select @S_SNO=SNO
from SC join C on SC.CNO=C.CNO
where C.CNAME=@C_NAME
group by SNO,GRADE
having GRADE=max(GRADE)
return @S_SNO
end
go
use jwt
go
print dbo.C_MAX('math')
--9.在教学管理数据库中,创建用户定义函数SNO_INFO,根据输入的课程名称,输出选修该门课程的学生学号、姓名、性别、系部、成绩。
use jwt
go
if exists (select * from sysobjects where name='SNO_INFO'and type='IF')
drop function SNO_INFO
go
create function SNO_INFO
(@C_NAME nchar(8))
returns TABLE
as
return (select SN0,SNAME,SEX,COLLEGE,GRADE
from S join (SC join C on SC.CNO=C.CNO) on S.SN0=SC.SNO
where CNAME=@C_NAME)
go
use jwt
go
select * from SNO_INFO('sql')
go