Mysql笔试题
1.查询Student表中的所有记录的Sname、Ssex和Class列。
SELECT Sname,Ssex,Class FROM Students;
2.查询教师所有的单位即不重复的Depart列。
SELECT DISTINCT Depart FROM Teachers;
3.查询Student表的所有记录。
SELECT * FROM Students;
4.查询Score表中成绩在60到80之间的所有记录。
SELECT * FROM Scores WHERE Degree BETWEEN 60 AND 80;
5.查询Score表中成绩为85,86或88的记录。
SELECT * FROM Scores WHERE Degree IN (85,86,88);
6.查询Student表中“95031”班或性别为“女”的同学记录。
SELECT * FROM Students WHERE Class='95031' OR Ssex='女';
7.以Class降序查询Student表的所有记录。
SELECT * FROM Students ORDER BY Class DESC;
8.以Cno升序、Degree降序查询Score表的所有记录。
SELECT * FROM Scores ORDER BY Cno,Degree DESC;
9.查询“95031”班的学生人数。
SELECT COUNT(1) AS StuNum
FROM Students
WHERE Class='95031';
10.查询Score表中的最高分的学生学号和课程号。
SELECT Sno,Cno FROM Scores ORDER BY Degree DESC LIMIT 1;
11.查询‘3-105’号课程的平均分。
SELECT AVG(Degree)
FROM Scores
WHERE Cno='3-105';
12.查询Score表中至少有5名学生选修的并以3开头的课程的平均分数。
SELECT Cno,AVG(Degree)
FROM Scores
WHERE Cno LIKE '3%'
GROUP BY Cno
HAVING COUNT(Sno) >= 5;
13.查询最低分大于70,最高分小于90的Sno列。
SELECT Sno
FROM Scores
GROUP BY Sno
HAVING MAX(Degree)<90 AND MIN(Degree)>70;
14.查询所有学生的Sname、Cno和Degree列。
SELECT Sname,Cno,Degree
FROM Students INNER JOIN Scores
ON(Students.Sno=Scores.Sno)
ORDER BY Sname;
15.查询所有学生的Sno、Cname和Degree列。
SELECT Sno,Cname,Degree
FROM Scores INNER JOIN Courses
ON(Scores.Cno=Courses.Cno)
ORDER BY Sno;