how to maintain table orignal order after using dense_rank() in sql server -
i have table :-
id | name | address | code -----+---------+----- 1 | b | b-11 | 111 2 | b | b-11 | 123 3 | | a-11 | 456 4 | | a-11 | 789
i need output : -
id | name | address | code | addressid -----+---------+------+---------- 1 | b | b-11 | 111 | 1 2 | b | b-11 | 123 | 1 3 | | a-11 | 456 | 2 4 | | a-11 | 789 | 2
when use following sql statement desired format order of table gets changed. can tell me how addressid
column values without changing table order.
select id, name, address, code, dense_rank() on (order name,address) addressid table1
with above code wrong output -
id| name | address | code | addressid --+------+---------+------+---------- 3 | | a-11 | 456 | 1 4 | | a-11 | 789 | 1 1 | b | b-11 | 111 | 2 2 | b | b-11 | 123 | 2
as said - don't have order, unless explicitly specify it - that's need - specify ordering want have adding order id
existing query:
select id, name, address, code, dense_rank() on (order name,address) addressid table1 order id
Comments
Post a Comment