对学员成绩表进行查询,查询任意两科及格的学员数量
2012-07-23 16:34
260 查看
对学员成绩表进行查询
要求:
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
要求:
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
相关文章推荐
- 一个查询数据库所有表的存储过程(允许按表名模糊查询一级按显示数量进行分页)
- >如果有年纪为S2的学生,就查询参加S2学科考试的学员学号,科目编号,考试成绩,考试时间
- Dialplan 手写的简单学员成绩电话查询系统
- sql查询技巧,按时间分段进行分组,每半小时一组统计组内记录数量
- Student类对学生成绩进行查询
- 对List进行子查询及分组
- hql语句传递一个数组进行查询
- hibernate学习笔记(二)------------使用criteria进行查询
- mysql查询成绩排名显示-两种排名方式
- Hibernate中利用Criteria进行数据库表数据的增加查询。
- 用Cg对任意形状的物体进行凹凸贴图(含源码)
- Java对MySQL数据库进行连接、查询和修改
- 写一条SQL查询出每门科目的最高分,按照科目进行分组
- 【mongoDB】Java中使用条件操作符进行查询 推荐
- 查询总成绩排名前三的学生成绩信息
- Python登录大连交通大学教务在线实现成绩查询
- 查询如下课程平均成绩和及格率的百分数(用"1行"显示),使用两种方式实现。
- 2011年上半年软考成绩查询网站,祝贺自己顺利通过2011年系统分析师考试!
- 用SQL进行函数查询
- vue.js实现成绩查询、新增、修改