通过总和计算密集等级
样本数据:
学生 | 分数 | 科目 |
---|---|---|
Stud1 | 100 | sub1 |
Stud1 | 400 | sub2 |
Stud1 | 500 | sub3 |
Stud2 | 200 | sub1 |
Stud2 | 700 | sub2 |
Stud2 | 800 | sub3 |
Stud2 | 900 | sub4 |
Stud3 | 300 | sub1 |
Stud3 | 600 | sub2 |
Stud4 | 1000 | sub1 |
尝试按学生分区并按分数总和排序,如下所示dense_rank()
。还有多个其他列,并且由于数据很大,因此尝试避免此处的任何连接。
预期输出:
学生 | 分数 | subject | ds_rnk |
---|---|---|---|
Stud1 | 100 | sub1 | 2 |
Stud1 | 400 | sub2 | 2 |
Stud1 | 500 | sub3 | 2 |
Stud2 | 200 | sub1 | 1 |
Stud2 | 700 | sub2 | 1 |
Stud2 | 800 | sub3 | 1 |
Stud2 | 900 | sub4 | 1 |
Stud3 | 300 | sub1 | 3 |
Stud3 | 600 | sub2 | 3 |
Stud4 | 1000 | sub1 | 2 |
提前致谢!
Sample data:
student | marks | subject |
---|---|---|
stud1 | 100 | sub1 |
stud1 | 400 | sub2 |
stud1 | 500 | sub3 |
stud2 | 200 | sub1 |
stud2 | 700 | sub2 |
stud2 | 800 | sub3 |
stud2 | 900 | sub4 |
stud3 | 300 | sub1 |
stud3 | 600 | sub2 |
stud4 | 1000 | sub1 |
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:
student | marks | subject | ds_rnk |
---|---|---|---|
stud1 | 100 | sub1 | 2 |
stud1 | 400 | sub2 | 2 |
stud1 | 500 | sub3 | 2 |
stud2 | 200 | sub1 | 1 |
stud2 | 700 | sub2 | 1 |
stud2 | 800 | sub3 | 1 |
stud2 | 900 | sub4 | 1 |
stud3 | 300 | sub1 | 3 |
stud3 | 600 | sub2 | 3 |
stud4 | 1000 | sub1 | 2 |
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以分两个阶段计算sum和dense_rank:
You can calculate sum and dense_rank in two stages: