如何分组固定计数范围? [英] How to group in fixed count ranges?

查看:88
本文介绍了如何分组固定计数范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一张有两列(student_id,成绩)的表。



student_id是一个整数,成绩是一个十进制数字。



如果我有1000个学生,并且想按年级将他们分组,每组10个学生。



这应该产生100组。第一组得分最高的10个等级,最后一组得分最低的10个等级。



我该怎么做?
始终欢迎优化。



非常感谢。



Joao

解决方案

ntile 将按存储桶数量进行排名。

 从学生

Let's say I have one table with two columns (student_id,grade).

student_id is an integer and grade is a decimal number.

In case I have 1000 students and want to group them ordered by grade in groups of 10 students each.

Just to be clear, this should produce 100 groups. The first group cointains the 10 highest grades and the last group contains the 10 lowest grades.

How should I do that ? Optimization is always welcome.

Thank you very much.

Joao

解决方案

ntile will give a ranking by an amount of buckets.

select student_id, ntile(100) over (order by grade desc) from student

这篇关于如何分组固定计数范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆