mode
On this page
Returns the most frequent non-NULL value.
Syntax
mode(<expr>)Arguments
| Argument | Type | Description |
|---|---|---|
<expr> | Any type | Input value. |
Returns
Returns the same type as the input. Returns NULL for empty input or when every value is NULL. If multiple values have the same highest frequency, any of them may be returned.
Examples
Summarize the most frequent method in completed payment events for each store.
VALUES
('north', 'card'), ('north', 'wallet'), ('north', 'card'), ('north', 'card'),
('south', 'wallet'), ('south', 'card'), ('south', 'wallet')
SELECT $0 AS store, $1 AS method
GROUP BY store
AGGREGATE mode(method) AS common_method
ORDER BY store+-------+---------------+
| store | common_method |
+-------+---------------+
| north | card |
| south | wallet |
+-------+---------------+