求一条语句的写法
有成绩表ChengJi:
Name(varchar)名字
Chengji(int)名称
class(varchar)班级
目的:选出每个班级分数最高的学生的记录
但是下面的语句不行:
Select Name,Max(ChengJi) AS CHENG From ChengJi Group by Class
这个语句只能选择在聚合函数中的或是在Group by语句中出现的字段
请大家帮帮忙怎么选择所有字段,选择成绩最大的,用班级分组
------解决方案--------------------select t.* from ChengJi t where not exists(select 1 from ChengJi where Class=t.Class and ChengJi> t.ChengJi)
------解决方案--------------------select v.Name,t.cheng from
ChengJi as v inner join
(select class,max(chengJi) as cheng from ChengJI group by class) as t
on v.class=t.class and v.chengji=t.cheng
------解决方案--------------------楼上两为都能实现,老大的简单感觉楼主可以采用
------解决方案--------------------有成绩表ChengJi:
Name(varchar)名字
Chengji(int)名称
class(varchar)班级
目的:选出每个班级分数最高的学生的记录
select a.* from 成绩表 a,
(select class , max(ChengJi) as ChengJi from 成绩表 group by class) b
where a.class = b.class and a.chengji = b.chengji
------解决方案--------------------up
------解决方案--------------------有成绩表ChengJi:
Name(varchar)名字
Chengji(int)名称
class(varchar)班级
目的:选出每个班级分数最高的学生的记录
select * from ChengJi a
where not exists(select * from ChengJi where class=a.class and Chengji> a.Chengji)
--or:
select a.* from ChengJi a
inner join
(
select class,max(Chengji) Chengji from Chengji
group by class
)b
on a.class=b.class