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 

1mode() 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.

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

Mode by Group 

Find the most common value for each group.

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

Related Documentation