Conditions are used to define what logic is to be executed based on the status of some condition being satisfied. Filters are expressions used to specify a subset of the data items.
Case statement. Expressions are evaluated in order, and the first to evaluate to true is returned.ELSE returns a default value if no statement evaluates to true. If there is no ELSE condition and no case evaluates to true, then NULL is returned.Operator
Copy
Ask AI
CASEWHEN exprs THEN result1[ WHEN exprs THEN result2 ]…[ ELSE default ]END
Example
Copy
Ask AI
CASEWHEN state = 'CA' THEN 1WHEN score > 500 THEN 1ELSE 0END
Filter with a where clause. The where clause only applies to the aggregation preceding the FILTER keyword. Otherwise, the WHERE clause is identical to any other WHERE clause.Operator
Copy
Ask AI
aggregate_function( * ) [ FILTER ( WHERE filter_exprs ) ]
Example
Copy
Ask AI
COUNT(*) FILTER ( WHERE state = 'CA' OR state = 'TX')