Analog of ROW_NUMBER() OVER(PARTITION BY)

5,717 views
Skip to first unread message

kot...@gmail.com

unread,
Feb 21, 2017, 11:18:58 AM2/21/17
to ClickHouse
Hi,

I'm trying to make query selecting popular events chains.

Does ClickHouse have something like Transact-SQL function ROW_NUMBER() OVER(PARTITION BY)?
Also, that kind of queries could be done if ClikHouse JOIN supports not only equal conditions in USING section.
I've tried to use rowNumberInAllBlocks() and rowNumberInBlock() functions but blocks seems to can't be able to defined manually.

Maybe there are some specific tricks that can be used to calculate most popular events chains?

Alex Zatelepin

unread,
Feb 28, 2017, 8:41:28 AM2/28/17
to ClickHouse
Greetings!

There are no general-purpose window functions in ClickHouse at the moment. However there is a clause in SELECT statement that might help in your case: LIMIT n BY column - select first n rows for each value of column. Unfortunately it is undocumented at the moment, but here is a github issue with some comments and examples: https://github.com/yandex/ClickHouse/issues/111

Is LIMIT BY enough for your problem?

kot...@gmail.com

unread,
Mar 1, 2017, 4:20:25 AM3/1/17
to ClickHouse
Thanks.
Actually, it isn't enough, but it seems to be very useful.

voros...@phystech.edu

unread,
Oct 22, 2018, 5:24:00 PM10/22/18
to ClickHouse
Hello!
Are there any updates on window functions in ClickHouse? SUM() OVER(PARTITION BY) would be very useful 

вторник, 28 февраля 2017 г., 16:41:28 UTC+3 пользователь Alex Zatelepin написал:

Denis Zhuravlev

unread,
Oct 22, 2018, 8:37:48 PM10/22/18
to ClickHouse
>Are there any updates on window functions in ClickHouse?
it depends, but generally no updates.

>SUM() OVER(PARTITION BY) would be very useful
it's the same as  sum() group by

inv2004

unread,
Jun 1, 2019, 5:05:28 PM6/1/19
to ClickHouse
Denis,

Please find that the result is not the same, because OVER do not GROUP-BY result, but adds calculated value (calculated over group-by).

Regards,
Reply all
Reply to author
Forward
0 new messages