Skip to content
Advertisement

SQL: Get row number which increases every time a value changes

I have the following table in Vertica:

The table is ordered by column_1 and column_3. I would like to add a row number, which increases every time when column_1 or column_3 change their value. It would look something like this:

I tried using partition over but I can’t find the right syntax.

Advertisement

Answer

Vertica has the CONDITIONAL_CHANGE_EVENT() analytic functions. It starts at 0, and increments by 1 every time the expression that makes the first argument undergoes a change.

Like so:

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement