[2017年整理]SQL实验课平时考核.doc
文本预览下载声明
jxgl数据库表及表字段说明:
Students(sno, sname,class,ssex,bday,bplace,mgrade,photo,sfzh,zxf)
该表是学生基本信息表 其中:sno-学号,sname-姓名,class-班级,ssex-性别,
bday-出生日期,bplace-籍贯,mgrade-入学成绩,photo-照片,sfzh-身份证号码,zxf-总学分
Course(cno,cname,cpno,credit)
该表是课程情况表 其中:cno-课程号,cname-课程名称,cpno-先修课程号,credit—学分
SC(term,sno,cno,grade,point)
该表是学生选课成绩表 其中:term-学期,sno-学号,cno-课程号,grade-成绩,point-绩点
TC(term,class,cno,tno,period)
该表是教师上课情况表 其中: term-学期;class-班级;cno-课程号;tno-教师编号; period-学时
Teachers (tno,tname,ps,wday,dept,pay,marry,resume)
该表是教师基本情况表:其中tno-教师编号;tname-教师姓名;ps-职称; wday-入校日期;dept-系别;pay-工资;marry-婚否;resume-简历
熟悉以上关系图,有助于搞清表之间关系,写出正确的查询
在jxgl中完成下列查询select Students.sno(sno两个表都有所以要前缀),sname,class,SC.grade
from Students,SC
where Students.sno=SC.sno and cno=0000011
order by grade desc
--(2)由于输入有误,百分制成绩有超出100分的,查询所有课程成绩超过100分的记录,并用update语句将它(们)改为100分
update SC
set grade=100
where grade100
--(3)查询所有学习了课程的学生信息,查询结果按学号的升序排列
select *
from Students,SC
where Students.sno=SC.sno
order by Students.sno
--(4)分组统计每个选修了课程的学生所选修的课程数,要求显示学生学号、姓名以及选课数量
select s.sno as sno,s.sname as sname,count(SC.cno) as 课程数量
from Students s,SC
where s.sno=SC.sno
group by s.sno,s.sname
select t.*
from Teachers t,TC
where t.tno=TC.tno and cno=0000011
--(6)查询尚未分配授课教师的课程信息
select *
from Course
where cno in (select cno from TC where tno is NULL)
select Course.*
from Course,TC
where TC.tno is NULL and TC.cno=Course.cno
--(7)查询所有课程的先修课程,要求显示当前课程号、课程名以及先修课程号、课程名(若没有则这部分显示NULL)
select c.cno as 当前课程号,c.cname as 课程名,c.cpno as 先修课程号
from Course cselect a.cno,a.cname,a.cpno as 先修课程号,b.cname as 先修课程名
from Course a left join Course b on a.cpno=b.cno
select *
from Students
where sname like 王%
select sno as 编号,sname as 姓名
Into xb
from students
where len(sname)=2
ALTER TABLE xb ADD 身份 nvarchar(8) DEFAULT 教师
update xb set 身份=学生 where 身份 is null
insert Into xb(编号,姓名)
select tno,tname
from teachers
where len(tname)=2
’学生’ as 身份 from Stuents where sname like ‘__’
union all
select tno,tname,’教师’ as 身份 from Tea
显示全部