日期:2014-05-17 浏览次数:20416 次
select classname,score,addtime from 选课表 a join 课程表 b on a.classid=b.classid join
(select userid,classid,score=max(score),addtime=max(addtime) from 考试成绩表 k1 where not exists(select 1 from 考试成绩表 k2 where k1.userid=k2.userid and
k1.classid=k2.classid and k1.addtime<k2.addtime) group by userid,classid) c on a.userid=c.userid and a.classid=c.classid
create table 选课表(userid int,classid int)
create table 课程表(classid int,classname varchar(10))
create table 考试成绩表(userid int,classid int,score float,addtime datetime)
go
insert 选课表
select 1,1 union all
select 1,2 union all
select 1,3 union all
select 2,2 union all
select 2,6
insert 课程表 values(1,'语文')
insert 课程表 values(2,'数学')
insert 课程表&