Skip to main content

Window Functions

ClickHouse supports the standard grammar for defining windows and window functions. The following features are currently supported:

FeatureSupport or workaround
ad hoc window specification (count(*) over (partition by id order by time desc))supported
expressions involving window functions, e.g. (count(*) over ()) / 2)not supported, wrap in a subquery (feature request)
WINDOW clause (select ... from table window w as (partition by id))supported
ROWS framesupported
RANGE framesupported, the default
INTERVAL syntax for DateTime RANGE OFFSET framenot supported, specify the number of seconds instead
GROUPS framenot supported
Calculating aggregate functions over a frame (sum(value) over (order by time))all aggregate functions are supported
rank(), dense_rank(), row_number()supported
lag/lead(value, offset)Not supported. Workarounds:
1) replace with any(value) over (.... rows between <offset> preceding and <offset> preceding), or following for lead
2) use lagInFrame/leadInFrame, which are analogous, but respect the window frame. To get behavior identical to lag/lead, use rows between unbounded preceding and unbounded following


GitHub Issues

The roadmap for the initial support of window functions is in this issue.

All GitHub issues related to window funtions have the comp-window-functions tag.


These tests contain the examples of the currently supported grammar:

Postgres Docs

MySQL Docs