SQL(mysql)语句查询--navicat 工具---(1)

-- 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 > 60 and degree < 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 ASC,degree DESC
-- 9、 查询“95031”班的学生人数。
SELECT count(sno) FROM students where class = '95031'
-- 10、查询Score表中的最高分的学生学号和课程号。
SELECT cno,sno,degree 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 AVG( degree) from scores where cno LIKE '3%' GROUP BY cno HAVING count(sno) > 5

猜你喜欢

转载自blog.csdn.net/OYY_90/article/details/82736769