1.查询李老师的个数
SELECT *
FROM teachers
WHERE tname LIKE '李%';
2.查询Student表中的所有记录的Sname,ssex,和class列
SELECT sname,ssex,class
FROM students;
3.查询教师所有的单位即不重复的Depart列
SELECT DISTINCT depart
FROM teachers;
4.查询Student表的所有记录
SELECT *
FROM students;
5.查询Score表中成绩在60到80之间的所有记录
SELECT *
FROM scores
WHERE degree BETWEEN 60 AND 80;
6.查询Score表成绩为85,86或88的记录
SELECT *
FROM scores
WHERE degree IN ('85','86','88');
7.查询Student表中‘95031’班或性别为女的同学记录
SELECT *
FROM students
WHERE class = '95031' OR ssex = '1';
8.以class降序查询student表的所有记录
SELECT *
FROM students
ORDER BY class;
9.以cno升序,degree降序查询score表的所有记录
SELECT *
FROM scores
ORDER BY cno ASC , degree DESC;
10.查询95031班的学生人数
SELECT COUNT(*)
FROM students
WHERE class=95031;
11.统计出所有学生的总成绩
SELECT SUM(degree)
FROM scores;
12.统计出所有学生的平均成绩
SELECT AVG(degree)
FROM scores;
13.统计出所有学生的最低成绩
SELECT MIN(degree)
FROM scores;
14.统计每个学生的总成绩
SELECT sno,SUM(degree)
FROM scores
GROUP BY sno;
15.统计每门课及格的学生数
SELECT cno,COUNT(*)
FROM scores
WHERE degree>=60
GROUP BY cno;
16.统计每门课程都及格的学生编号
SELECT sno,cno,degree
FROM scores
GROUP BY sno
HAVING MIN(degree)>=60;
17.统计每门课的最低成绩;
SELECT cno,MIN(degree)
FROM scores
GROUP BY cno;
18.查询出名字叫周梅每门课的成绩;
SELECT sc.`degree`
FROM students st JOIN scores sc
ON st.`sno`=sc.`sno`
WHERE st.`sname`='皮皮虾'
GROUP BY sc.`cno`;
19.查询出每个老师教的学生人数
SELECT COUNT(*),te.tname
FROM (teachers te JOIN courses co ON te.`tno`=co.`tno`)JOIN scores sc ON sc.`cno`=co.`cno`
GROUP BY te.`tno`
HAVING COUNT(*);
20.查询选修某课程的同学人数多于5人的教师姓名;
SELECT te.`tname`,COUNT(*)
FROM (teachers te JOIN courses co ON te.`tno`=co.`tno`)JOIN scores sc ON sc.`cno`=co.`cno`
GROUP BY sc.`cno`
HAVING COUNT(*)>=5;
21.查询出选课人数不低于2人的课程和老师姓名;
SELECT sc.`cno`,te.`tname`
FROM (teachers te JOIN courses co ON te.`tno`=co.`tno`)JOIN scores sc ON sc.`cno`=co.`cno`
GROUP BY sc.`cno`
HAVING COUNT(*)>=2;
22.查询出每个老师教的学生人数
SELECT te.tname,COUNT(*)
FROM (teachers te JOIN courses co ON te.`tno`=co.`tno`)JOIN scores sc ON sc.`cno`=co.`cno`
GROUP BY te.`tno`
HAVING COUNT(*);
23.查询出每个老师教的课程的平均成绩
SELECT AVG(sc.degree)
FROM (teachers te JOIN courses co ON te.`tno`=co.`tno`)JOIN scores sc ON sc.`cno`=co.`cno`
GROUP BY te.`tname`
24.查询出李四老师教的课程的平均成绩
SELECT te.tname,sc.cno,AVG(sc.degree)
FROM (teachers te JOIN courses co ON te.`tno`=co.`tno`)JOIN scores sc ON sc.`cno`=co.`cno`
WHERE te.tname='李四';
查询各个课程号与相应的选课人数
SELECT co.cno,COUNT(*)
FROM course co JOIN studentCourse st ON co.cno=st.cno
GROUP BY co.cno
HAVING COUNT(*);
找出没有选择c2课程的学生信息
SELECT st.*
FROM (studentCourse sc JOIN student st ON sc.sno=st.sno)JOIN course co ON co.cno=sc.cno
WHERE co.cname NOT IN 'c2';
查询所有课程均及格的学生学号及姓名
SELECT st.sno,st.sname
FROM (studentCourse sc JOIN student st ON sc.sno=st.sno)JOIN course co ON co.cno=sc.cno
GROUP BY co.cname
HAVING MIN(grade)<60;
查询平均分不及格的课程号和平均成绩
SELECT co.cno,AVG(sc.grade)
FROM course co JOIN studentCourse st ON co.cno=st.cno
GROUP BY co.cname
HAVING AVG(sc.grade)>=60;
找出各门课程的平均成绩,输出课程名和平均成绩
SELECT co.cname,AVG(sc.grade)
FROM course co JOIN studentCourse st ON co.cno=st.cno
GROUP BY co.cname
查询最低分的同学的sno,cno和degree
--1.首先查询出最低成绩
SELECT MIN(degree)
FROM scores;
--2.其次在把最低条件按照条件去嵌套查询
SELECT *
FROM scores
WHERE degree IN(SELECT MIN(degree)
FROM scores);
查询和李军同性别的的所有同学的姓名
--1.首先查询出李军的性别是?
SELECT ssex
FROM students
WHERE sname='李军';
--2.其次在把李军的性别作为where条件去查询(嵌套);
SELECT sname
FROM students
WHERE ssex IN(SELECT ssex
FROM students
WHERE sname='李军');
查询和李军同性别并且同班的姓名
--1.首先查询出李军的性别是?
SELECT ssex
FROM students
WHERE sname='李军';
--2,其次查询出李军所在的班级
SELECT class
FROM students
WHERE sname='李军';
--3.最后把李军的性别跟班级作为条件去查询
SELECT sname
FROM students
WHERE ssex IN(SELECT ssex
FROM students
WHERE sname='李军')AND class IN(SELECT class
FROM students
WHERE sname='李军');
查询男教师及所上的课程
--1.在老师表格中查询男老师的tno
SELECT tno
FROM teachers
WHERE tsex='男';
--2.把查询出男老师的tno作为条件在课程表中查询出课程名
SELECT cname
FROM courses
WHERE tno IN(SELECT tno
FROM teachers
WHERE tsex='男');
查询student表中不性王的同学记录
SELECT *
FROM students
WHERE sname NOT LIKE '王%';
2018-11-26测试流程&数据库复习
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 近期有客户需要皕杰报表与阿里ads分析型数据兼容情况的测试,为此,我方专门租用了阿里ADS分析数据库,做了皕杰报表...