select a.学生姓名,b.考试时间 as 最新考试时间 from a join b on a.学生id=b.学生id and 考试时间=(select max(考试时间) from b t where 学生id=b.学生id)
select a.学生姓名,b.考试时间 from a,b t where a.学生id=t.学生id and not exists(select 1 from b where 学生id=t.学生id and 考试时间>t.学生id)
有两张表 a 学生id, 学生姓名,.... b 学生id, 考试时间, 考试成绩我现在想显示 学生姓名,最新的该学生的考试时间,最新的该学生的考试成绩 该怎么写sqlselect top 1 a.学生姓名,b.考试时间,b.考试成绩 from a inner join b on a.id=b.id order b.考试时间 desc
select a.学生姓名 , t.考试时间, t.考试成绩 from a , b t where a.学生id = t.学生id and t.考试时间 = (select max(考试时间) from b where 学生id = t.学生id)select a.学生姓名 , t.考试时间, t.考试成绩 from a , b t where a.学生id = t.学生id and t.考试时间 = (select 1 from b where 学生id = t.学生id and 考试时间 > t.考试时间)
5楼写错一点,更改为如下: select a.学生姓名 , t.考试时间, t.考试成绩 from a , b t where a.学生id = t.学生id and t.考试时间 = (select max(考试时间) from b where 学生id = t.学生id)select a.学生姓名 , t.考试时间, t.考试成绩 from a , b t where a.学生id = t.学生id and not exists (select 1 from b where 学生id = t.学生id and 考试时间 > t.考试时间)
from a join b on a.学生id=b.学生id
and 考试时间=(select max(考试时间) from b t where 学生id=b.学生id)
a.学生姓名,b.考试时间
from
a,b t
where
a.学生id=t.学生id
and
not exists(select 1 from b where 学生id=t.学生id and 考试时间>t.学生id)
a 学生id, 学生姓名,....
b 学生id, 考试时间, 考试成绩我现在想显示 学生姓名,最新的该学生的考试时间,最新的该学生的考试成绩 该怎么写sqlselect top 1 a.学生姓名,b.考试时间,b.考试成绩
from a inner join b on a.id=b.id
order b.考试时间 desc
from a , b t
where a.学生id = t.学生id and t.考试时间 = (select max(考试时间) from b where 学生id = t.学生id)select a.学生姓名 , t.考试时间, t.考试成绩
from a , b t
where a.学生id = t.学生id and t.考试时间 = (select 1 from b where 学生id = t.学生id and 考试时间 > t.考试时间)
select a.学生姓名 , t.考试时间, t.考试成绩
from a , b t
where a.学生id = t.学生id and t.考试时间 = (select max(考试时间) from b where 学生id = t.学生id)select a.学生姓名 , t.考试时间, t.考试成绩
from a , b t
where a.学生id = t.学生id and not exists (select 1 from b where 学生id = t.学生id and 考试时间 > t.考试时间)