FILTER Clause

Applies to: ✅ Data 360 SQL ✅ Tableau Hyper API

Filters which rows are passed to an aggregate function based on a condition.

  • <aggregate_function>: Any aggregate function.
  • <condition>: A boolean expression that determines which rows to include.

Returns the result of the aggregate function applied only to rows where the condition is true.

  • Only rows where the condition evaluates to true are passed to the aggregate.
  • Normal rules for empty groups apply: aggregates with no matching rows return NULL.
  • Exceptions: count(*) and count(expression) return 0 for empty groups.
  • Allows computing multiple filtered aggregations in a single query.

Count total rows and filtered rows.

Returns:

total_casesblue_cases
42

Calculate different aggregates with different filters.

Returns:

coloravg_priceavg_sfphone_pricesfphone_count
black50501
blue30451
red17NULL0

Sum values matching a condition.