cr_do_percent_rank.sql

This page documents a preview version. v2.23 Preview
Preview includes features under active development and is for development and testing only.
For production, use the latest stable version (v2024.1).

Save this script as cr_do_percent_rank.sql.

create or replace procedure do_percent_rank(no_of_buckets in int)
  language sql
as $body$
  insert into results(method, bucket, n, min_s, max_s)
  with
    measures as (
      select
        score,
        (percent_rank() over w) as measure
      from t4_view
      window w as (order by score))
    ,
    bucket as (
      select
        bucket(measure::numeric, 0::numeric, 1::numeric, $1) as bucket,
        score
      from measures)

  select
    'percent_rank',
    bucket,
    count(*),
    min(score),
    max(score)
  from bucket
  group by bucket;
$body$;