接上一篇
31.将学号和姓名用下划线连接,显示在一列。(sql中的连接符用‘+’)
select stuno+'_'+stuname "学号_姓名"
from t_student;
32.显示教授的所有资料
select*
from T_TEACHER
where teatitle='教授'
33.将所有的分数显示为与60分的差值,同时也显示原分数。
select score,'score-60'=score-60
from T_SCORE
34.显示姓张的男生的姓名
select stuname,stusex
from T_STUDENT
where stuname like '张%' and stusex='男'
35.查询高级职称以下的教师姓名,高级职称以下为副教授和讲师
select teaname
from T_TEACHER
where teatitle !='教授'
--或
select teaname
from T_TEACHER
where teatitle in('副教授','讲师')
36.学校需要请学生对教授的教学作评价,因此需要通知相关学生。请查询出:教授所教过的课程,有哪些学生选过?列出他们的姓名
select distinct coursename,teaname,stuname
from T_STUDENT,T_COURSE,T_TEACHER,T_SCORE
where T_STUDENT.stuno=T_SCORE.stuno
and T_COURSE.courseno=T_SCORE.courseno
and T_COURSE.teano=T_TEACHER.teano
and teatitle='教授'
37.查询郭莉芳的哪些科目期末考试没有及格?列出这些科目的名称和分数
select stuname,coursename,score
from T_COURSE,T_STUDENT,T_SCORE
where T_STUDENT.stuno=T_SCORE.stuno
and stuname='郭丽芳'
and T_COURSE.courseno=T_SCORE.courseno
and type='期末' and score<60
38.统计学生姓名的数量
select count(distinct stuname)"学生数量"
from T_STUDENT
39.查询学校有多少名教师
select count(distinct teaname) '教师数量'
from T_TEACHER
40.查询为“梁天”的教师讲了多少门课
select count (distinct coursename)
from T_COURSE,T_TEACHER
where T_TEACHER.teano=T_COURSE.teano and teaname='梁天'
41.查询参加过考试的学生数量
select count(distinct stuno) '参加考试学生数'
from T_SCORE
42.查询郭丽芳选了多少门课
select count(distinct courseno)
from T_STUDENT,T_SCORE
where T_STUDENT.stuno=T_SCORE.stuno and stuname='郭丽芳'
43.查询课程C002的期末考试平均分
select avg(distinct score)'平均分'
from T_SCORE
where courseno='c002'
44.查询课程C003的期中考试总分
select sum( distinct score) '总分'
from T_SCORE
where courseno='c002' and Type='期中'
45.查询学校所有考试记录的总分
select sum(score)'总分'
from T_SCORE
46.查询课程C004的期末考试最高分
select max(score)
from T_SCORE
where courseno='c004' and Type='期末'
47.查询每个教师讲授的课程数量,并将其姓名和课程数量显示出来
select teaname,count(courseno)"课程数量"
from T_COURSE,T_TEACHER
where T_TEACHER.teano=T_COURSE.teano
group by teaname
48.查询郭丽芳每门课的平均分,显示课程名称和平均分
select coursename,avg(score)'平均分'
from T_SCORE,T_STUDENT,T_COURSE
where T_SCORE.stuno=T_STUDENT.stuno
and T_SCORE.courseno=T_COURSE.courseno
and stuname='郭丽芳'
group by coursename