mysql-练习题

1:自行创建测试数据
2:查询“生物”课程比“物理”课程成绩高的所有学生的学号

SELECT B.student_id FROM
(SELECT score.student_id,score.number FROM score INNER JOIN course ON score.course_id = course.cid WHERE course.cname="生物") as A
    INNER JOIN
(SELECT score.student_id,score.number FROM score INNER JOIN course ON score.course_id = course.cid WHERE course.cname="物理") as B
        ON A.student_id=B.student_id AND A.number>B.number;

3:查询平均成绩大于60分的同学的学号和平均成绩;

SELECT student_id,avg(number) 平均成绩 FROM score GROUP BY student_id HAVING avg(number)>60;

4:选出学生的学号,姓名,选课数,总成绩

select student.sname,count(score.course_id),ifnull(sum(score.number),0) as name ,max(student.sid) as sid from student left join score on student.sid = score.student_id group by student.sname;

5:查询老师中名字第一个字为李的人

select tname from teacher where tname REGEXP "^波";

你可能感兴趣的:(mysql-练习题)