cr_do_cume_dist.sql

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

Save this script as cr_do_cume_dist.sql.

create or replace procedure do_cume_dist(no_of_buckets in int)
  language sql
as $body$
  insert into results(method, bucket, n, min_s, max_s)
  with
    measures as (
      select
        score,
        (cume_dist() 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
    'cume_dist',
    bucket,
    count(*),
    min(score),
    max(score)
  from bucket
  group by bucket;
$body$;