数据库中几种常见的题型
来源:互联网 发布:小米手环2淘宝50天预发 编辑:程序博客网 时间:2024/05/16 19:23
--统计本班的平均成绩,如果平均分在70分以上,则显示“成绩优秀”,并显示出最好成绩及学员姓名,如果在70分以下则显示“成绩较差”,并显示出最差成绩及学员姓名。
declare @score int
select @score=AVG(score) from Score
IF(@score>70)
BEGIN
print '成绩优秀'
--select Max(score)as '成绩',max(studentname)as '姓名' from score,student where student.studentid=score.studentid
select top 1 studentname as '姓名' from score,student where student.studentid=score.studentid order by score desc
END
ELSE
BEGIN
print '成绩较差'
--select MIN(score)as '成绩',min(studentname)as '姓名' from score,student where student.studentid=score.studentid
select top 1 studentname as '姓名' from score,student where student.studentid=score.studentid order by score asc
END
-- 本次考试成绩较差,假定要提分,确保每人成绩都通过。提分规则很简单,先每人都加2分,看是否都通过,如果没有全部通过,每人再加2分,再看是否都通过,如此反复提分,直到所有人都通过为止 ,提分不能超过100分
declare @score int
while(1=1)
begin
select top 1 @score=score.score from score order by score.score asc
if(@score>=60)
break;
UPDATE score set score=score+2
UPDATE score set score=100 where score>100
end
select convert(nvarchar(8),student.studentname)as '姓名',score.score as '成绩',
case
when score>=90 then '优'
when score>=80 then '良'
when score>=60 then '中'
else '不及格'
end AS '评价'
from score join student on score.studentid=student.studentid
-- 根据如下规则对机试成绩进行反复加分,直到平均分超过85分为止。请编写T-SQL语句实现:
--90分以上: 不加分
--80-89分: 加1分
--70-79分: 加2分
--60-69分: 加3分
--60分以下: 加4分
declare @score int
while(1=1)
begin
select @score=AVG(score) from score
if(@score>85)
break;
UPDATE score set score=score+1 where score >=80 and score<=89
UPDATE score set score=score+2 where score >=70 and score<=79
UPDATE score set score=score+3 where score >=60 and score<=69
UPDATE score set score=score+4 where score <=60
end
--把13-1等一系列这样的数字分离
select txt from demo
order by CONVERT(int, left(txt,charindex('-',txt)-1)),
CONVERT (int,right(txt,len(txt)-charindex('-',txt)))
select ID,txt ,substring(txt,1,charindex('-',txt)-1),
STUFF(txt,1,charindex('-',txt),'') from demo
- 数据库中几种常见的题型
- CTF常见的题型
- 单链表的常见题型汇总
- 常见易错点的程序题型
- 关于二叉树的常见题型
- 有关链表的常见题型
- 关于数组操作的常见题型
- 数据库题型
- 常见题型解法
- 面试常见题型总结
- 动态规划常见题型
- 链表常见题型
- javaweb常见面试题型
- CTF常见题型
- 一类常见的矩阵快速幂题型 总结
- 动态规划算法常见题型
- 数据库常用语句面试题型
- 数据库关系模式题型大全
- 访问指针所指向的位置
- java 序列化版本的作用
- 9. 规则特例
- 在Struts2中集成Spring详细讲解
- 10. 结束语
- 数据库中几种常见的题型
- 无效区域 更新区域 重画 WM_PAINT 的关系和机制(转载总结)
- fs/binfmt_aout.c:270: error: 'SEGMENT_SIZE' undeclared
- pushlet简介
- 根据sessionid获取session的被Servlet2.1抛弃getsession方法的解决方案
- linux很有用的命令
- jdk配置
- C++技巧:理解inline的使用和避免
- java中cookie的使用方法