Want to learn more on NTILE()

后端 未结 5 2120
耶瑟儿~
耶瑟儿~ 2020-12-08 02:19

I was reading on RANKING function for ms sql. I understand the others function except NTILE(). Lets say if i have this data:

   StudentID     MARKS  
              


        
5条回答
  •  余生分开走
    2020-12-08 02:55

    It will arrange the data in descending order of marks and then split it into 2 groups.

    If the data cannot be split into equal groups, then the first few groups will have more rows than the latter groups.

    So NTILE(2) will give you

    StudentID       MARKS       NTILE  
          S5           93           1 
          S3           91           1 
          S2           83           1
          S4           83           2
          S1           75           2 
    

    Similarly NTILE(3) will give you

    StudentID       MARKS       NTILE  
          S5           93           1 
          S3           91           1 
          S2           83           2
          S4           83           2
          S1           75           3  
    

提交回复
热议问题