2018-7-29 21:44:40
数据库练习题答案
http://www.cnblogs.com/wupeiqi/p/5748496.html
发现数据库就是记住语句熟练操作,掌握表与表之间的关系就好啦!
和几个朋友打了电话,谈了谈人生,发现,还是我那句话
人的选择不同,自然追求的东西不同!
努力学习,要为以后做打算,加油!!努力!努力!再努力!越努力越幸运!
我命由我不由天!!!!
6.查询没学过'李平老师'老师课的同学的学生姓名(连表操作很多!)
select *from score where num>60; -- select *from course; -- select teacher_id,count(cname) from course group by teacher_id -- select *from course left join teacher on course.teacher_id=teacher.tid; -- select *from student left join class on student.class_id=class.cid; -- 临时表 -- select *from (select * from score where num>60)as b; -- 1.自行创建测试数据 -- 2.查询'生物'课程比'物理'课程成绩搞得所有学生的学号 -- 所有生物成绩 -- SELECT score.sid,score.student_id,course.cname,score.num FROM score left join course on score.course_id=course_id where course.cname='生物'; -- 所有物理成绩 -- SELECT score.sid,score.student_id,course.cname,score.num FROM score left join course on score.course_id=course_id where course.cname='物理'; select A.student_id from (SELECT score.sid,score.student_id,course.cname,score.num FROM score left join course on score.course_id=course_id where course.cname='物理')as A INNER JOIN (SELECT score.sid,score.student_id,course.cname,score.num FROM score left join course on score.course_id=course_id where course.cname='生物')as B on A.student_id =B.student_id where A.num >B.num; -- 3.查询平均成绩大于60分的同学的学号和平均成绩 显示学生姓名 -- select B.student_id ,student.sname,B.ccc from(select student_id ,avg(num)as ccc from score GROUP BY student_id HAVING avg(num)>60)as B -- left join B.student_id=student.sid; -- 4.查询所有同学的学号,姓名,学课数,总成绩 -- select score.student_id,student.sname ,count(student_id),sum(num) from score left join student on score.student_id=student.sid GROUP BY score.student_id; -- 5.查询李老师个数 -- 6.查询没学过'李平老师'老师课的同学的学生姓名 -- 李平老师任教课程id -- select course.cid from course left join teacher on course.teacher_id=teacher.tid where teacher.tname='李平老师; -- SELECT -- * -- FROM -- ( -- SELECT -- score.student_id -- FROM -- score -- WHERE -- course_id NOT IN ( -- SELECT -- course.cid -- FROM -- course -- LEFT JOIN teacher ON course.teacher_id = teacher.tid -- WHERE -- teacher.tname = '李平老师') -- )as B -- left join student on student.sid=B.sid;