9951 explained code solutions for 126 technologies


clickhouseUsing variables in queries


WITH '2020' AS min_year SELECT * FROM tbl WHERE toYear(date) > min_yearctrl + c
WITH

allows defining user variables

'2020'

user variable value

min_year

user variable name

SELECT * FROM tbl

sample select


Usage example

WITH '2020' AS min_year SELECT * FROM tbl WHERE toYear(date) > min_year
output
┌───────date─┬─col────┬─val─┬─age─┐
│ 2022-01-07 │ Donald │   0 │   0 │
│ 2022-01-10 │ Donald │   0 │   0 │
│ 2022-01-11 │ Donald │   0 │   0 │
...