SQL:查找(多个)教授的最佳学生按等级

发布于 2025-02-10 20:24:02 字数 1138 浏览 0 评论 0原文

必须

教授
成绩最佳
找到每个
学生
​。

SELECT Prof, Student, MIN(Grade)
FROM x
GROUP BY Prof

​这样:

A学生
A11.0
b31.2
.........

所以学生2-也是A教授最好的学生 - 失踪了。我该如何解决?

I have to find the students with the best grade of each professor with this given table "x":

ProfStudentGrade
A11.0
A21.0
A55.0
A61.3
B31.2
B42.0
.........

The result should look like this:

ProfStudentGrade
A11.0
A21.0
B31.2
.........

I already tried grouping the first table by Prof with:

SELECT Prof, Student, MIN(Grade)
FROM x
GROUP BY Prof

But the result gives me only one Student per professor like this:

ProfStudentGrade
A11.0
B31.2
.........

So student 2 - who is also professor A's best student - is missing. How do I fix this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

庆幸我还是我 2025-02-17 20:24:02

就可以使用两种可能性

一旦选择了每个教授的最低成绩,

SELECT Prof, Student, Grade
FROM x
WHERE  (Prof,  Grade) IN (SELECT Prof,  MIN(Grade)
FROM x
GROUP BY Prof)

,并将TAT用作Resilset fpr in条款。或作为加入的桌子,大桌子上通常更快

SELECT Prof, Student, Grade
FROM x JOIN
(SELECT Prof,  MIN(Grade) mingrade
FROM x
GROUP BY Prof) t1 x.prof = t1.prof AND x.Grade = t1.mingrade

You ave two possibilities

Once you select the minimum of grades for every professor and use tat as resilset fpr an IN clause.

SELECT Prof, Student, Grade
FROM x
WHERE  (Prof,  Grade) IN (SELECT Prof,  MIN(Grade)
FROM x
GROUP BY Prof)

Or as joined table, which is on big table usually faster

SELECT Prof, Student, Grade
FROM x JOIN
(SELECT Prof,  MIN(Grade) mingrade
FROM x
GROUP BY Prof) t1 x.prof = t1.prof AND x.Grade = t1.mingrade
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文