RosettaCodeData/Task/Bin-given-limits/DuckDB/bin-given-limits-2.duckdb
2025-08-11 18:05:26 -07:00

14 lines
481 B
Text

# "pretty print" the histogram as a table
create or replace function pp(data, limits) as table (
with hist as (
select histogram(boundary) as h
from bins(data, limits) t(value, boundary)
),
upper as (select h['inf'::DOUBLE][1] as upper from hist)
select '< ' || x::VARCHAR as bin, (select coalesce(h[x][1],0) from hist) as frequency
from unnest(limits) _(x)
union all
select '< inf', upper from upper
);
from pp(getvariable('data'), getvariable('limits'));