mysql 链式查询_mysql连接查询

本文提供了一种SQL查询方法,用于从成绩表中找出每个课程的最高分和最低分及其对应的学生信息。通过两次SELECT语句分别实现了最大值和最小值的检索。

希望能有点帮助,分两段执行。

select b.name 'course_name', a.number 'num_max', a.student_id 'student_id', c.name 'student_name' from score a,course b,student c

where a.number = (select max(number) from score b where a.course_id=b.course_id)

and a.course_id=b.course_id

and a.student_id=c.student_id;

select b.name 'course_name', a.number 'num_min', a.student_id 'student_id', c.name 'student_name' from score a,course b,student c

where a.number = (select min(number) from score b where a.course_id=b.course_id)

and a.course_id=b.course_id

and a.student_id=c.student_id;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值