【发布时间】:2014-06-16 11:56:59
【问题描述】:
我有这样的表格:
ExerciseAttempt(attemptId, ExerciseId, Score, studentId)
ExerciseMeta(ExerciseId, ParentId)
每个练习都有一个家长。父母可以有很多孩子练习。现在我想找到只考虑父母的一个孩子(得分最高的那个)的记录。
例如:
ExericeAttempt:
attemptId | ExerciseId | Score | studentId
1 | 10 | 18 | 10001
2 | 11 | 12 | 10001
3 | 12 | 20 | 10001
4 | 13 | 22 | 10001
5 | 13 | 21 | 10001
ExerciseMeta:
ExerciseId | ParentId
10 | 100
11 | 100
12 | 101
13 | 101
对于这些表格,结果应该是
attemptId | ExerciseId | Score | studentId
1 | 10 | 18 | 10001
4 | 13 | 22 | 10001
同样可以多次尝试同一个练习。 如何在 SQL SERVER 中实现这一点?
【问题讨论】:
标签: sql-server sql-server-2008 greatest-n-per-group