Student表:

方法一:嵌套查询
select s2.* from
(
select class,max(age) Age from
Student
group by
class
) s1
left join
Student s2
on s1.class=s2.class
and s1.age=s2.age;
结果集:

方法二:with as
with max_age as(
select class,max(age) Age from
Student
group by
class
)
select stu.*
from
max_age ma
join
Student stu
on
ma.class=stu.class
and ma.age=stu.age
结果集:

本文介绍了两种SQL查询方法,一种是使用嵌套查询实现,另一种是利用with as语法完成。这两种方法均可用于从Student表中筛选出每个班级年龄最大的学生信息。

3975

被折叠的 条评论
为什么被折叠?



