C#--存储过程综合查询的编写

存储过程的综合查询

根据班级查询
根据全校查询
根据考试成绩查询
根据缺考人员查询
使用存储过程可以一个方法查询多个

这里写图片描述


编写数据库存储过程

基本框架

这里写图片描述

存储过程语句

这里写图片描述

use StudentManageDB
go

if exists(Select * from sysobjects where name='usp_ScoreQuery')
drop procedure usp_ScoreQuery
go
create procedure usp_ScoreQuery
@ClassName varchar(50),@stuCount int output,@avgCSharp int output,
@avgDB int output,@absentCount int output
as
    if(len(@ClassName)=0)--[查询全部]
        begin           
            --查询全校考试成绩列表
            Select Students.StudentId,StudentName,ClassName,CSharp,SQLServerDB
            from Students
            inner join ScoreList on Students.StudentId=ScoreList.StudentId
            inner join StudentClass on Students.ClassId = StudentClass.classId
            --查询考试统计信息
            select @stuCount=Count(*),@avgCSharp=avg(CSharp),@avgDB=avg(SQLServerDB)
            from ScoreList
            select @absentCount=Count(*)from Students where StudentId not in 
            (Select StudentId from ScoreList)
            --查询没有参加考试的学生名单
            Select StudentName from  Students where StudentId not in(Select StudentId 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值