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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 RANKING???

Author  Topic 

twhitle
Starting Member

11 Posts

Posted - 2007-12-14 : 12:56:24
I have two columns, one with a percentage amount and one that I want to rank best to worst based on that percentage amount. In 2000, how would this be possible?????????

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2007-12-14 : 13:09:26
select val, percentage from mytable order by percentage desc

??


elsasoft.org
Go to Top of Page

twhitle
Starting Member

11 Posts

Posted - 2007-12-14 : 13:39:15
I didn't word this right. You must be like wtf.

I would like to create a ranking function based on a field that has been coverted to a decimal, a percentage field, and another field that is a number divided by it's total header. I am sure that this requires an actual ranking function. I would really appreciate an example of a ranking function if you have one. It would be greatly appreciated.

quote:
Originally posted by jezemine

select val, percentage from mytable order by percentage desc

??


elsasoft.org

Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2007-12-14 : 14:28:44
This code uses an identity column to create a rank.

declare @t table (
Seq int not null identity(1,1) primary key clustered,
val int not null )

declare @rank table (
Rank int primary key clustered,
val int not null )

-- Load values in order by val column to be ranked
insert into @t (val)
select top 100 percent val
from
(
select top 200
-- Generate random test data values
val=(abs(checksum(newid()))%14)+347
from
master.dbo.sysobjects a
order by
a.id
) b
order by
val

-- Load into rank table
insert into @rank ( Rank,val )
select top 100 percent
Rank = min(Seq),
val
from
@t
group by
val
order by
min(Seq)

select * from @rank


Results:

(200 row(s) affected)


(14 row(s) affected)

Rank val
----------- -----------
1 347
12 348
26 349
39 350
50 351
65 352
81 353
103 354
120 355
136 356
153 357
161 358
175 359
190 360

(14 row(s) affected)






CODO ERGO SUM
Go to Top of Page
   

- Advertisement -