请教了公司里的人,都不会,求兄弟们帮忙!!!!
有两个表a和b,a储存着所有班级信息,b储存着所有学生id、age、sex和classname。
现在我要提取几个班级(该班级必须符合一个条件:班里age最小的学生,sex=女)。
请问sql该如何实现?
------解决方案--------------------
上面错了。 应该用这个!
select c1.*
from classes c1,
(select classname,sex,age from students
group by classname,sex
having sex='F' and age=min(age)
) c2,
(select classname,min(age) as age_1 from students
group by classname
having age=min(age)
) c3
where c1.classname=c2.classname and c2.classname=c3.classname and c2.age=c3.age_1
order by c1.classid
go