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 |
|
lovecherry
Starting Member
3 Posts |
Posted - 2006-12-08 : 23:19:58
|
| Hi, does anybody know how to assign a column of natural numbers to a sorted table? I mean, I have sorted the table, now I want to EXPLICITLY show on the table that "this is #1, this is #2..." Can anybody help? Thanks! |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2006-12-08 : 23:22:02
|
| Add an IDENTITY column to the table.Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
lovecherry
Starting Member
3 Posts |
Posted - 2006-12-08 : 23:31:42
|
| Actually what I meant to do is to get quintiles. In order to do that, I do cumulative sum first, and then just SELECT CASE. The way I do cumulative sum is like this, but I realized it only worked when I have a column of natural number with my descendingly sorted sales.SELECT a.DayCount, a.Sales, SUM(b.Sales) AS RunningTotalFROM Sales a CROSS JOIN Sales b ON b.DayCount <= a.DayCountGROUP BY a.DayCount , a.SalesORDER BY a.DayCount , a.Sales |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-12-09 : 02:49:27
|
| 1 Are you tring to find Running Total? If you use front end application, you can do easily there2 To do in sql is ineffecient and you need to have unique key for that3 If not, You can copy the data to temp table that has identity column and do Running TotalMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|