1 小红 语文 67
2 小红 数学 45
3 小红 英语 87
4 小张 语文 98
5 小张 数学 55
6 小张 英语 45
7 小李 语文 34
8 小李 数学 64
9 小李 英语 72
查询出的结果
4 小张 语文 98
8 小李 数学 64
3 小红 英语 87谢谢各位帮忙!在线等,立马给分!
2 小红 数学 45
3 小红 英语 87
4 小张 语文 98
5 小张 数学 55
6 小张 英语 45
7 小李 语文 34
8 小李 数学 64
9 小李 英语 72
查询出的结果
4 小张 语文 98
8 小李 数学 64
3 小红 英语 87谢谢各位帮忙!在线等,立马给分!
select a.* from tb a
join (select 科目,max(成绩) from tb group by 科目) b
on a.科目=b.科目 and a.成绩=b.成绩
--5楼的有问题
select * from tb
where not exists(select 1 from tb b where tb.课程=b.课程 and tb.成绩 <b.成绩)
select t.* from 表 t where not exists(select 1 from 表 where 科目=t.科目 and 成绩>t.成绩)
2
select ID ,Name,課程 max(分數)from tb group by ID ,Name,課程
2
select ID ,Name,課程 max(分數)from tb group by ID ,Name,課程
create table tb(id int,name varchar(20),kemu varchar(20),score int)
go
insert into tb select 1,'小红','语文',67
insert into tb select 2,'小红','数学',45
insert into tb select 3,'小红','英语',87
insert into tb select 4,'小张','语文',98
insert into tb select 5,'小张','数学',55
insert into tb select 6,'小张','英语',45
insert into tb select 7,'小李','语文',34
insert into tb select 8,'小李','数学',64
insert into tb select 9,'小李','英语',72
go
select * from tb;
select * from tb where not exists(select 1 from tb b where tb.kemu=b.kemu and tb.score<b.score);
go
drop table tb;
gO
这个应该可以啊 select t.* from 表 t where not exists(select 1 from 表 where 科目=t.科目 and 成绩>t.成绩)还有可以利用CHECK什么的也可以
from course t join
(select coursename,max(chengji) as l from course group by coursename) u
on u.coursename=t.coursename and t.chengji=u.l