对学员成绩表进行查询,查询任意两科及格的学员数量

 

对学员成绩表进行查询

要求:

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)

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

 

转载于:https://www.cnblogs.com/liwangsmart/archive/2012/07/23/2605180.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值