Skip to main content
On this page

Kater SQL Functions Derive

KATER__BUCKET

A label for the band of numbers that each value is in.

Family: Derive

Syntax

KATER__BUCKET(field, edges [, labels => [label, ...]])

Arguments

Required

ArgumentDescription
fieldThe number to put in bands.
edgesThe numbers where one band stops and the next starts, from the lowest to the highest. A list such as [10, 100].

Optional

ArgumentDescription
labelsA label for each band, from the lowest band up. Give one more label than edges. A list such as ['Small', 'Large'].

Returns

Text, or NULL where the field is empty.

Usage notes

  • Each band includes its lower edge. With [25, 100], 25 is in the band 25 – 100, and 100 is in ≥ 100.
  • Without labels, the bands are named < 25, 25 – 100 and ≥ 100.

Example

This Sandbox query reads the sample shop’s orders. The table shows the rows that Kater gave.

SELECT
KATER__BUCKET(orders.amount, [50, 100, 200]) AS "Amount Band",
EVAL(orders.count_distinct__order_id) AS "Orders"
FROM kater_dataset.orders AS orders
GROUP BY
KATER__BUCKET(orders.amount, [50, 100, 200])
ORDER BY
KATER__MIN(orders.amount)
Amount BandOrders
< 50690
50 – 100854
100 – 200592
≥ 200833
null31

Compiles to

The call compiles to the same SQL on DuckDB and on Snowflake.

CASE
WHEN orders.amount IS NULL
THEN NULL
WHEN orders.amount < 50
THEN '< 50'
WHEN orders.amount < 100
THEN '50 – 100'
WHEN orders.amount < 200
THEN '100 – 200'
ELSE '≥ 200'
END

See also