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
| Argument | Description |
|---|---|
field | The number to put in bands. |
edges | The numbers where one band stops and the next starts, from the lowest to the highest. A list such as [10, 100]. |
Optional
| Argument | Description |
|---|---|
labels | A 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 band25 – 100, and 100 is in≥ 100. - Without labels, the bands are named
< 25,25 – 100and≥ 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 ordersGROUP BY KATER__BUCKET(orders.amount, [50, 100, 200])ORDER BY KATER__MIN(orders.amount)| Amount Band | Orders |
|---|---|
| < 50 | 690 |
| 50 – 100 | 854 |
| 100 – 200 | 592 |
| ≥ 200 | 833 |
| null | 31 |
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'ENDSee also
- Groups and flags
- Other functions in Derive:
KATER__MAP,KATER__PERIODS_SINCE