mysql练习题3:求"001"课程成绩大于“002”课程成绩的所有学生信息

学生信息表为 stu

id(学号)  name(姓名)    sex(性别)    age(年龄)

学生成绩表为result

id(学号)     pid(课程号)  score(成绩)

select id,name,sex,age

from stu

where id = (select id from result as a,result as b

where (a.id = b.id) 

and (a.pid = "001" and a.score >b.score));

可以用内连接查询如下(更好理解但是代码量相对比较大):

select id,name,sex,age

from stu t1

inner join

(select id from

(select id,score from result where pid = "001") a

inner join

(select id,score from result where pid = "002") b

on a.id = b.id and a.score > b.score) t2

on t1.id = t2.id; 

发布了27 篇原创文章 · 获赞 8 · 访问量 1511

猜你喜欢

转载自blog.csdn.net/qq_43824618/article/details/104631609
今日推荐