我有两个这样的表:
Table1
________
StudentNumbers ExamType
1234 1
2343 2
3345 5
3454 1
5465 2
...
Table2
________
StudentNumbers ExamType ExamDate School Area
1234 1 0825 warren ny
1234 1 0829 north nj
1233 2 0921 north nj
2343 1 0922 warren ny
2343 1 0925 north ny
...
我需要通过使用 Table1 中特定 ExamType 的数据从 Table2 中找出每个学生的最大 ExamDate。到目前为止我已经想出了这个,但这似乎不正确:
Select t2.StudentNumbers, t2.ExamType, max(t2.ExamDate), t2.School, t2.Area
from Table2 as t2
Join Table1 as t1 on
t1.StudentNumbers = t2.StudentNumbers
where t2.ExamType = 1
我在选择列表中收到错误,因为它不包含在聚合函数或 group by 子句中
它基本上应该返回:
StudentNumbers ExamType ExamDate School Area
1234 1 0829 north nj
2343 1 0925 north ny