SQL利用函数或存储过程求男或女的总分平均分

--函数
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 '女'

评论

h
hw_7864

⭐️ Admin快速开发: https://show.cool-admin.com/

赞 0
h
hw_7864

⭐️ 官方文档: https://cool-js.com

赞 0
h
hw_7864

⭐️ chatgpt在线体验: https://cool-js.com/ai/chat-vip/index.html?r=helloworld

赞 0