MODE

Applies to: ✅ Data 360 SQL ✅ Tableau Hyper API

Returns the most frequent input value. If there are multiple equally frequent values, returns an arbitrary one.

Syntax

mode() WITHIN GROUP (ORDER BY <sort_expression>)

Arguments

Required

  • <sort_expression>: An expression of any sortable type that determines the value to find the mode of.

Returns

Returns the same type as the sort expression. Returns NULL if no rows are selected.

Considerations

  • This is an ordered-set aggregate function.
  • NULL values in the sorted input are ignored.
  • When multiple values have the same highest frequency, the choice between them is arbitrary.

Examples

Find Most Common Value

Get the most frequently occurring category.

SELECT mode() WITHIN GROUP (ORDER BY category) AS most_common_category
FROM products;

Mode by Group

Find the most common value for each group.

SELECT region, mode() WITHIN GROUP (ORDER BY product_type) AS popular_product
FROM sales
GROUP BY region;

Related Documentation