title: how to calculate percentile in postgres
body: <p>I Have table called timings where we are storing 1 million response timings for load testing , now we need to divide this data into 100 groups i.e. - first 500 records as one group and so on , and calculate percentile of each group , rather than average.</p>
  
  <p>so far i tried this query </p>
  
  <pre><code>Select quartile
       , avg(data) 
       , max(data) 
    FROM (
  
          SELECT data
               , ntile(500) over (order by data) as quartile
            FROM data
         ) x
   GROUP BY quartile
   ORDER BY quartile
  </code></pre>
  
  <p>but how do i have find the percentile</p>