Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9142091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:43:53+00:00 2026-06-17T09:43:53+00:00

I was reading on RANKING function for ms sql. I understand the others function

  • 0

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  
      S1           75  
      S2           83
      S3           91
      S4           83
      S5           93  

So if i do a NTILE(2) OVER(ORDER BY MARKS desc) what will be the result and why?
And what if it is a NTILE(3)?
Simple explaination anyone?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:43:54+00:00Added an answer on June 17, 2026 at 9:43 am

    Think of it as buckets, NTILE(2) will make 2 buckets, half the rows will have the value 1 and the other half the value 2

    example

    create table  #temp(StudentID char(2),    Marks  int) 
    insert #temp  values('S1',75 ) 
    insert #temp  values('S2',83)
    insert #temp  values('S3',91)
    insert #temp  values('S4',83)
    insert #temp  values('S5',93 ) 
    
    
    select NTILE(2) over(order by Marks),*
    from #temp
    order by Marks
    

    Here is the output, since you have an uneven number of rows, bucket 1 will have 1 row more

    1   S1  75
    1   S2  83
    1   S4  83
    2   S3  91
    2   S5  93
    

    If you add one more row

    insert #temp  values('S6',92 ) 
    

    Now both buckets have 3 rows

    1   S1  75
    1   S2  83
    1   S4  83
    2   S3  91
    2   S6  92
    2   S5  93
    

    In reality I have never used NTILE in production code but I can see the use where you need to split the results into n number of buckets

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Reading Real world Haskell i found some intresting question about data types: This pattern
Reading through this , I came to the bit on default values for function
Reading the Scala by Example book and there is this example when Martin explains
Reading through this excellent article about safe construction techniques by Brain Goetz, I got
Reading the documentation I thought this code would write logs to a file in
Reading on SQL Server Book online and my understanding SQL Server Buffer Pool or
I was just reading an article about different ranking algorithms . One thing I'm
Reading some topics I found this piece of code, and I'm wondering, how does
Reading along with the agile book, it says this in a footnote: ... You
reading the docs i see that the glGetTexImage2d() function has a 'type' parameter. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.