2

我有一个Access包含Grads表的数据库:

Grads
 - studentId 
 - courseId 
 - tryNumber
 - semesterId 
 - finalGrad

如何studentName, courseName, courseId, finalGrade从 max tryNumber(last try) 行获取所有信息 () ?

4

4 回答 4

4

如果您只想要带有maxtrynumber 的一行,那么您应该可以使用:

select g.studentid,
  g.courseid,
  g.trynumber,
  g.semesterid,
  g.finalgrade
from grads g
inner join
(
  select max(tryNumber) MaxTry
  from grads
) m
  on g.trynumber = m.maxtry

如果您想返回每个学生max(tryNumber),那么您可以使用:

select g.studentid,
  g.courseid,
  g.trynumber,
  g.semesterid,
  g.finalgrad
from grads g
inner join
(
  select studentid, max(tryNumber) MaxTry
  from grads
  group by studentid
) m
  on g.trynumber = m.maxtry
  and g.studentid = m.studentid
于 2013-03-14T11:02:44.080 回答
0

这应该适合你:

SELECT studentName, 
       courseName, couseId, 
       finalGrade, MAX(tryNumber) 
FROM grads
GROUP BY studentName, courseName, couseId, finalGrade
于 2013-03-14T10:59:33.803 回答
0

您可以使用:

Select studentName, courseName, courseId, finalGrade From Grads
Where tryNumber=(Select MAX(tryNumber) From Grads)
于 2013-03-14T11:02:10.647 回答
-1

select top 1 * from Grads order by tryNumber desc

于 2013-03-14T10:59:53.267 回答