9951 explained code solutions for 126 technologies


clickhouseSelect sumIf query example


SELECT sumIf(age, date < '2022-01-01') FROM tblctrl + c
sumIf

sum specified column value if expression is true

age

name of the column to sum

date < '2022-01-01'

expression to check (should we add this row value to the total sum)

tbl

table to select data from


Usage example

SELECT sumIf(age, date < '2022-01-01') FROM tbl
output
┌─sumIf(age, less(date, '2022-01-01'))─┐
│                                  125 │
└──────────────────────────────────────┘