In PostgreSQL, I have a table with a column that has long repeats of 0's and 1's. I would like to create another column that ranks these with repeating ranks. Here is an example of what I'd like to see:
Column | New column |
---|---|
0 | 1 |
0 | 1 |
0 | 1 |
1 | 2 |
1 | 2 |
1 | 2 |
1 | 2 |
0 | 3 |
0 | 3 |
0 | 3 |
0 | 3 |
0 | 3 |
1 | 4 |
1 | 4 |
0 | 5 |
0 | 5 |
0 | 5 |
and so on. Can the table functions with rank be used effectively to do this? Or is this something that is beyond the window function capabilities? Thanks.