--函数
alter function xb
(
@xingbie varchar(2)
)
returns table
as
return
( select a.sex,SUM (b.score)as 总分,AVG(b.score)as 平均分
from stu3 as a full join stu4 as b on a .snum=b.cnum
where sex =@xingbie
group by a.sex
)
go
select * from xb ('女')
--存储过程
alter procedure xb1(@xingbie varchar(2))
as
select a.sex,SUM (b.score)as 总分,AVG(b.score)as 平均分
from stu3 as a full join stu4 as b on a .snum=b.cnum
where sex =@xingbie
group by a.sex
go
exec xb1 '女'
SQL利用函数或存储过程求男或女的总分平均分
点赞
收藏