Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
dirac
Starting Member
12 Posts |
Posted - 2008-01-17 : 13:19:21
|
| Hi, is it possible in sql to query a table by giving the groups numbers for example i have a two columned table and the data is like this: c1 c2------------ a red a blue a brown b white b gray c maroonand all iwant to get with a query is this: Nu. c1 c2--------------- 1 a red 1 a blue 1 a brown 2 b white 2 b gray 3 c maroonas you see the original order of the table and the datas of the columns are the same but i only want to give a group number like above:) |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
|
|
dirac
Starting Member
12 Posts |
Posted - 2008-01-17 : 13:49:40
|
| hi first of all thanks for your answer ,i think you got me wrong and i think you mean the row_number over partition on that page ilooked at that is amazing function but it gives an order in each group not numering the groups, |
 |
|
|
dirac
Starting Member
12 Posts |
Posted - 2008-01-17 : 14:04:12
|
| thank you anyway i have just found the solution from another site if anybody wonders i can share it can be possible with a dense_rank() function, thanks anyway. |
 |
|
|
sqlfresher2k7
Aged Yak Warrior
623 Posts |
Posted - 2008-01-17 : 15:16:24
|
| You got the results but below query also helps to get your desired results..SELECT DENSE_RANK () OVER (ORDER BY C1) AS 'C1', * from table |
 |
|
|
|
|
|