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
CASEWHEN exprs THEN result1[ WHEN exprs THEN result2 ]…[ ELSE default ]END
Example
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
aggregate_function( * ) [ FILTER ( WHERE filter_exprs ) ]
Example
COUNT(*) FILTER ( WHERE state = 'CA' OR state = 'TX')