select * from tb where 学号 in (select top 2 学号 from tb group by 学号 order by count(学号)) 这样写对吗!? -->再修改一下, select * from tb where 学号 in (select top 2 学号 from tb group by 学号 order by count(学号) desc )-->要降序排列,这样才能取到考试次数最多的前两名同学 iwl() 查询的是考试时间排在最前面的学号,时间,不是楼主要的
哦,谢谢! CSDN,的确快!! 结帖
create table A ( 学号 varchar(10), 考试时间 datetime) insert A select '0001','2005-02-26' union select '0002','2005-05-27' union select '0001','2005-05-26' union select '0003','2005-04-26' union select '0001','2005-03-26' union select '0002','2005-02-28' union select '0001','2005-07-26' union select '0002','2005-02-26' union select '0004','2005-08-26' select 学号,max(考试时间) from A where a.学号 in (select top 2 学号 from A group by 学号 order by count(*) desc) group by 学号
这样写对吗!?
select * from tb where 学号 in (select top 2 学号 from tb group by 学号 order by count(学号))
这样写对吗!? -->再修改一下,
select * from tb where 学号 in (select top 2 学号 from tb group by 学号 order by count(学号) desc )-->要降序排列,这样才能取到考试次数最多的前两名同学
iwl() 查询的是考试时间排在最前面的学号,时间,不是楼主要的
CSDN,的确快!!
结帖
( 学号 varchar(10),
考试时间 datetime)
insert A
select '0001','2005-02-26' union
select '0002','2005-05-27' union
select '0001','2005-05-26' union
select '0003','2005-04-26' union
select '0001','2005-03-26' union
select '0002','2005-02-28' union
select '0001','2005-07-26' union
select '0002','2005-02-26' union
select '0004','2005-08-26' select 学号,max(考试时间) from A where a.学号 in (select top 2 学号 from A group by 学号 order by count(*) desc)
group by 学号