Skip to main content
Skip to main content

anyIf

Description

The If combinator can be applied to the any aggregate function to select the first encountered element from a given column that matches the given condition.

Example Usage

In this example, we'll create a table that stores sales data with success flags, and we'll use anyIf to select the first transaction_ids which are above and below an amount of 200.

We first create a table and insert data into it:

The avgIf function will calculate the average amount only for rows where is_successful = 1. In this case, it will average the amounts: 100.50, 200.75, 300.00, and 175.25.

See also