Want to learn more on NTILE()

后端 未结 5 2104
耶瑟儿~
耶瑟儿~ 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:51

    Ntile without using partition clause, just divide the dataset based on the number in the ntile(number) such that : if no of rows are 7, example: 1,1,1,2,3,4,5 ntile(3) will give 3,2,2. How did i get 3,2,2?. Firstly assume 7 as 6 (one less to make it even), 6/3 gives 2,2,2 , then add +! to first partition. If the no.of rows are even then no problem. just divide the dataset

    Ntile using partition clause, just divide the dataset based on the values in dataset such that : if no of rows are 7,Example row values are: 1,1,1,2,3,4,5 then: ntile(3) partitioned by value will give: 1,2,3,1,1,1,1. How did i get this?. Firstly break the dataset based on values: here, 1,1,1 is one partiton, next all values form a different partition. Then start assigning ntile rank to each partition. Here, 1,1,1 will become 1,2,3 then continue with the next partition, you can pull the rank only till the number specified in ntile() function

提交回复
热议问题