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(*)andcount(expression)return 0 for empty groups. - Allows computing multiple filtered aggregations in a single query.
Count total rows and filtered rows.
Returns:
| total_cases | blue_cases |
|---|---|
| 4 | 2 |
Calculate different aggregates with different filters.
Returns:
| color | avg_price | avg_sfphone_price | sfphone_count |
|---|---|---|---|
| black | 50 | 50 | 1 |
| blue | 30 | 45 | 1 |
| red | 17 | NULL | 0 |
Sum values matching a condition.