I have table 'Z':
id|zone|name
------------
1 | 34 | a
2 | 14 | b
3 | 99 | c
4 | 99 | d
5 | 90 | e
6 | 99 | c
query
SELECT *,dense_rank() (OVER ORDER BY zone) FROM Z
return:
id|zone|name|dense_rank
-----------------------
1 | 34 | a | 2
2 | 14 | b | 1
3 | 99 | c | 4
4 | 99 | d | 4
5 | 90 | e | 3
6 | 99 | c | 4
First (less important) question is: is it possible have dense_rank sorted by id:
id|zone|name|dense_rank
-----------------------
1 | 34 | a | 1
2 | 14 | b | 2
3 | 99 | c | 3
4 | 99 | d | 3
5 | 90 | e | 4
6 | 99 | c | 3
But my final target is change the data partition when field 'zone' change. I need a table like this:
id|zone|name|window-function?
-----------------------
1 | 34 | a | 1
2 | 14 | b | 2
3 | 99 | c | 3
4 | 99 | d | 3
5 | 90 | e | 4
6 | 99 | c | 5
Any idea?
Thanks a lot
id
, but then 99 gets a3
but only for id3
and4
. Can you explain you are ranking these?