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)
 Calculating percentages

Author  Topic 

SunnyDee
Yak Posting Veteran

79 Posts

Posted - 2005-05-27 : 14:29:44
Hello everyone:

I have a table that looks like this:

Order Type Cust AppCount Percent

1 AB Smith 5
1 AB Smith 2
1 AB Smith 8
1 AB Jones 15
1 AB Ryan 12
1 AB Ryan 5


How can I have the percent column total the app count? I.E. For Smith the Percentages should be 33.33%, 13.33%, 53.33%. For Jones
the percentage should be 100%, etc. Any help is appreciated.

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2005-05-27 : 14:34:48
[code]
Select
order,
type,
cust,
appCount,
percent = convert(money,appCount)/convert(money,(Select sum(AppCount) From myTable where order=A.order and type=A.type and cust=A.cust)
From myTable A
[/code]

Corey

Secret Service Agent: Mr. President, you're urinating on me.
President Lyndon Johnson: I know I am. It's my prerogative.
Go to Top of Page
   

- Advertisement -