title: SQL Server - How to add a column of percentile values of another column?
body: <p>I'd like to have a calculated field that gives me the percentile of a column's value in a table. What is the best way to do so?  </p>
  
  <p>I have a table with only one column containing values ranging from 0 to 10000, randomly distributed. I want to add another column to tell me what the percentile of the value on the same row is with respect to all the other values in the original column.</p>
  
  <p>There are 2 definitions of percentile as explained here: <a href="http://onlinestatbook.com/chapter1/percentiles.html" rel="nofollow">http://onlinestatbook.com/chapter1/percentiles.html</a> .</p>
  
  <p>I am using the definition that I knew. Example: a value is at 25th percentile means 25% of the population is AT or below the value.</p>
  
  <p>The algorithm I am thinking of is below, I hope someone can translate it to SQL for me because I am an SQL beginner: </p>
  
  <p>For all the rows in my table, if the value is less than or equal to value in current row then count++. At the end of table, I do the division: count / number of rows to have my percentile. That's accurate enough for me because there are lots of rows.</p>