设为首页 加入收藏

TOP

对学员成绩表进行查询,查询任意两科及格的学员数量
2014-11-24 01:22:02 来源: 作者: 【 】 浏览:5
Tags:学员 成绩 进行 查询 任意 及格 数量

对学员成绩表进行查询,查询任意两科及格的学员数量
对学员成绩表进行查询
要求:
1.查处任意及格两科的学员数量
2.使用存储过程
大家看看下面这种查询办法可行吗,有没有更好的方法!
数据库表如下图:


name 代表学员名称 f1 \f2\f3\'f4代表课程成绩
存储过程如下:
方法一:
create proc tests
as
declare @agee float
set @agee=60
select count(name) from test a where (a.f1>=@agee and a.f2>=@agee) or (a.f1>=@agee and a.f3>=@agee) or (a.f1>=@agee and a.f4>=@agee) or
(a.f2>=@agee and a.f3>=@agee) or (a.f2>=@agee and a.f4>=@agee) or (a.f3>=@agee and a.f4>=@agee) www.2cto.com
exec tests
经过各位同仁的评论:还有两种更为简洁的方法,现在补充在下面,以方便各位的查看!
方法二:
select count(*)
from dbo.test where case when f1 >= 60 then 1 else 0 end +
case when f2 >= 60 then 1 else 0 end +
case when f3 >= 60 then 1 else 0 end +
case when f4 >= 60 then 1 else 0 end >= 2
方法三:
SELECT COUNT(*)
FROM dbo.test
WHERE f1 / 60 + f2 / 60 + f3 / 60 + f4 / 60 >= 2
作者 狼人天下
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇procedure emp_count 下一篇讲解往表中顺序插入N条记录的简易..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: