通过总和计算密集等级

发布于 2025-01-11 06:13:30 字数 1618 浏览 1 评论 0原文

样本数据:

学生分数科目
Stud1100sub1
Stud1400sub2
Stud1500sub3
Stud2200sub1
Stud2700sub2
Stud2800sub3
Stud2900sub4
Stud3300sub1
Stud3600sub2
Stud41000sub1

尝试按学生分区并按分数总和排序,如下所示dense_rank()。还有多个其他列,并且由于数据很大,因此尝试避免此处的任何连接。

预期输出:

学生分数subjectds_rnk
Stud1100sub12
Stud1400sub22
Stud1500sub32
Stud2200sub11
Stud2700sub21
Stud2800sub31
Stud2900sub41
Stud3300sub13
Stud3600sub23
Stud41000sub12

提前致谢!

Sample data:

studentmarkssubject
stud1100sub1
stud1400sub2
stud1500sub3
stud2200sub1
stud2700sub2
stud2800sub3
stud2900sub4
stud3300sub1
stud3600sub2
stud41000sub1

Trying to partition by student and order by sum of marks like below using dense_rank(). There are multiple other columns and since the data is big, trying to avoid any joins here.

Expected output:

studentmarkssubjectds_rnk
stud1100sub12
stud1400sub22
stud1500sub32
stud2200sub11
stud2700sub21
stud2800sub31
stud2900sub41
stud3300sub13
stud3600sub23
stud41000sub12

Thanks in advance!

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

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

发布评论

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

评论(1

长不大的小祸害 2025-01-18 06:13:30

您可以分两个阶段计算sum和dense_rank:

with cte as (
    select t.*, sum(marks) over (partition by student) as sum_marks
    from t
)
select cte.*, dense_rank() over (order by sum_marks desc) as dense_rankk
from cte

You can calculate sum and dense_rank in two stages:

with cte as (
    select t.*, sum(marks) over (partition by student) as sum_marks
    from t
)
select cte.*, dense_rank() over (order by sum_marks desc) as dense_rankk
from cte
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文