我有以下评估学生的表格:
StudentID | EvaluationStatusID| Date
1011010 | 1 |2013-11-07 20:31:51.000
1011020 | 1 |2013-11-08 13:23:51.000
1011010 | 2 |2013-11-08 20:31:51.000
1011020 | 3 |2013-11-09 20:31:51.000学生的评价经历了不同的阶段--“提交”、“评估”、“接受”等。
我需要得到每个学生的最新记录(按日期),以‘学生in评估状态in’的形式。
因此,在上面的数据中,我应该返回以下内容:
1011010-2
1011020-3在server 2008中,我如何获得它?
发布于 2014-01-20 11:49:59
SELECT StudentID +' ' +EvaluationStatusID
FROM tblTable T
WHERE T.Date = (SELECT MAX(TT.Date)
FROM tblTable TT
WHERE TT.StudentID = T.StudentID
)发布于 2014-01-20 13:03:10
试试这个:
With S1 as
(
select StudentID +''+EvaluationStatusID as Info,
ROW_NUMBER() OVER (PARTITION BY StudentID
ORDER BY StudentID) as RC
from students
)
select * from S1 where S1.RC in (Select MAX(S1.RC)from S1)
Group By Info, RChttps://stackoverflow.com/questions/21233105
复制相似问题