sumIf
Description
The If combinator can be applied to the sum
function to calculate the sum of values for rows where the condition is true,
using the sumIf aggregate combinator function.
Example usage
In this example, we'll create a table that stores sales data with success flags,
and we'll use sumIf to calculate the total sales amount for successful transactions.
The sumIf function will sum only the amounts where is_successful = 1.
In this case, it will sum: 100.50 + 200.75 + 300.00 + 175.25.
Calculate trading volume by price direction
In this example we'll use the stock table available at ClickHouse playground
to calculate trading volume by price direction in the first half of the year 2002.
Calculate trading volume by stock symbol
In this example we'll use the stock table available at ClickHouse playground
to calculate trading volume by stock symbol in 2006 for three of the largest tech
companies at the time.