title: Create column for the quantile number of a value in BigQuery
body: <p>I have a table with two columns: <code>id</code> and <code>score</code>. I'd like to create a third column that equals the quantile that an individual's <code>score</code> falls in. I'd like to do this in BigQuery's standardSQL.</p>
  
  <p>Here's <code>my_table</code>:</p>
  
  <pre><code>+----+--------+
  | id | score  |
  +----+--------+
  |  1 |      2 |
  |  2 |     13 |
  |  3 |     -2 |
  |  4 |      7 |
  +----+--------+
  </code></pre>
  
  <p>and afterwards I'd like to have the following table (example shown with quartiles, but I'd be interested in quartiles/quintiles/deciles)</p>
  
  <pre><code>+----+--------+----------+
  | id | score  | quaRtile |
  +----+--------+----------+
  |  1 |      2 |        2 |
  |  2 |     13 |        4 |
  |  3 |     -2 |        1 |
  |  4 |      7 |        3 |
  +----+--------+----------+
  </code></pre>
  
  <p>It would be excellent if this were to work on 100 million rows. I've looked around to see a couple solutions that seem to use <a href="https://stackoverflow.com/questions/22060430/whats-the-best-way-to-get-the-ids-of-rows-by-percentile-for-bigquery">legacy sql</a>, and the <a href="https://stackoverflow.com/questions/17997089/bigquery-rank-function-resources-exceeded">solutions using</a> <code>RANK()</code> functions don't seem to work for really large datasets. Thanks!</p>