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 |
|
tamancha.1
Starting Member
37 Posts |
Posted - 2010-04-21 : 17:02:01
|
| Here is my table:user_id time_stamp38441030 3/23/2010 14:06:3438441030 3/23/2010 14:06:3443477060 3/29/2010 18:03:2043477060 3/29/2010 18:03:2158635220 3/5/2010 13:11:4358635220 3/5/2010 13:11:4358635220 3/5/2010 13:40:3658635220 3/5/2010 13:41:1858635220 3/5/2010 13:42:58I want to create a new table, ordering each user_id by time and append a count column in front of it:user_id time_stamp imp_numb38441030 3/23/2010 14:06:34 138441030 3/23/2010 14:06:34 243477060 3/29/2010 18:03:20 143477060 3/29/2010 18:03:21 258635220 3/5/2010 13:11:43 158635220 3/5/2010 13:11:43 258635220 3/5/2010 13:40:36 358635220 3/5/2010 13:41:18 458635220 3/5/2010 13:42:58 5Please help.Thanks. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2010-04-21 : 17:59:10
|
| You don't need a new table just for this sequence. You can generate it in a SELECT like below.SELECT user_id,time_stamp, row_number () over (partition by user_id order by time_stamp)from table |
 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2010-04-21 : 17:59:39
|
|
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|
|