#【例6.10】查询student表中姓董的学生情况。
select * from student where sname like '董%';
#【例6.11】查询含有“系统”或“数字”的所有课程名称。
select * from course where cname regexp '系统|数字';
#【例6.12】求学生的总人数。
select count(*) AS 总人数 from student;
#【例6.13】查询通信专业学生的总人数。
select count(*) as 总人数 from student where speciality='通信';
#【例6.14】查询1201课程总分。
select sum(grade) as 课程1201总分 from score where cno='1201';
#【例6.15】查询8001课程的最高分、最低分、平均成绩。
select max(grade) as 课程8001最高分,min(grade) as 课程8001最低分,avg(grade) as 课程8001平均成绩
from score where cno='8001';
#【例6.16】查询各门课程的最高分、最低分、平均成绩。
select cno as 课程号,max(grade) as 最高分,min(grade) as 最低分,avg(grade) as 平均成绩
from score where not grade is null group by cno;
#【例6.17】查询平均成绩在90分以上的学生的学号和平均成绩。
select sno as 学号,avg(grade) as 平均成绩 from score group by sno having avg(grade)>90;
#【例6.18】查询至少有5名学生选修且以8开头的课程号和平均分数。
select cno as 课程号,avg(grade) as 平均分数 from score
where cno like'8%' group by cno having count(*)>5;
#【例6.19】将计算机专业的学生按出生时间降序排序。
select * from student where speciality='计算机' order by sbirthday desc;
#【例6.20】查询成绩表中成绩前3位学生的学号、课程号和成绩。
select sno,cno,grade from score order by grade desc limit 3 offset 0;
#【例6.21】采用交叉连接查询教师和和讲课地点所有可能组合。
select tname,location from teacher,lecture;
#【例6.22】查询每个学生选修课程的情况。
select student.*,score.* from student,score where student.sno=score.sno;