select case when数学>=80 then '优秀'when数学>=60 then '及格'else '不及格' end数学,
select case when英语>=80 then'优秀'when英语>=60 then '及格'else '不及格' end英语 from table select
(case when 语文>=80 then '优秀' when 语文>=60 then '及格' else '不及格') as 语文,
(case when 数学>=80 then '优秀' when 数学>=60 then '及格' else '不及格') as 数学,
(case when 英语>=80 then '优秀' when 英语>=60 then '及格' else '不及格') as 英语, from table
五.设计题(共40分)
在[Xk]数据库中有
课程表[Course]由课程编码(CouNo)、课程名称(CouName)、教师名(Teacher)等组成, 学生表[Student]由学号(StuNo)、学生姓名(StuName)、班级编号(ClassNo)等组成, 学生选课表[StuCou]由学号(StuNo)、课程编码(CouNo)等组成。
1.检索Xk数据库中的课程表(Course)中的教师名(Teacher)、课程编码(CouNo)、课
程名称(CouName),要求检索结果首先按照教师名降序排列,教师名相同时,则按照课程号升序排列。(5分)
select Teacher, CouNo, CouName from Course oredr by Teacher desc,CouNo
2. 使用IN关键字检索Xk数据库中的课程表(Course),要求检索课程编码(CouNo)不为
'004'、'007'、'013' (5分)
select CouNo from Course where CouNo not in ('004','007','013')
3. 从Xk数据库中的Student表中检索第二个字为'宝'的学生名字。(5分)
select StuName from Student where StuName like '_宝%'
4. 使用Transact-SQL语句在XK数据库中创建一个名为[p_StudentPara]的存储过程。该存
储过程能根据给定的班级返回该班级代码对应的Student表中的记录。并赋值查询班级代码为'20000001'和'20000002'的学生记录。(5分)
create proc p_StudentPara
@ ClassNo varchar(50)--班级编号 as begin
select * from Student where ClassNo=@ ClassNo end go
exec p_StudentPara '20000001' exec p_StudentPara '20000002'
5. 创建一个触发器,要求当插入、更新、删除StuCou表的选课记录时,能更新Course表
中相应的报名人数。(10分) create trigger ChangeData on StuCou
for insert,update,delete as begin
if(select count(*) from inserted)>0 update Course set People= People+1 if(select count(*) from deleted)>0 update Course set People= People-1 update StuCou SET CouNo='002' WHERE StuNo='00000011' AND CouNo='003 end go
6. 在SQL查询分析器的查询窗口中创建一个尺寸为5MB的逻辑名字为newxk的数据库, 3MB
的数据文件NEW_DATA.MDF存储在C:\\下,文件的最大尺寸为10MB,文件增量为1MB。2MB的事务日志文件NEW_LOG.LDF存储在C:\\下,文件的最大尺寸为15MB,文件的增量为1MB。(10分)
CREATE DATABASE newxk
ON
(NAME =NEW_data,
FILENAME ='C:\\NEW_data.mdf', SIZE=3,
MAXSIZE=10, FILEGROWTH=1) LOG ON
(NAME ='NEW_log',
FILENAME='C:\\NEW_log.ldf', SIZE =2MB, MAXSIZE= 15MB, FILEGROWTH=1MB) GO