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)
 Percentage Calculation

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-12-06 : 08:41:43
Samira writes "I need to find out a percentage value in a select SUM(CASE WHEN.... THEN WHEN.... THEN WHEN..... THEN ELSE 0 END) AS Percentage

how do i include the percentage calculation inside the query above?

Windows 2003 server
SQL 2000 server + sp 3"

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2004-12-06 : 09:20:37
Percentage of WHAT ?

In general, divide the each number by the total of all numbers to get the percentage, but I'm sure you already know that.

We need some more info to help you. sample data would help as well. in the meantime, consider this:

select
a.ID, a.value, (1.0 * a.value / b.total) as PCT
from
data a
inner join
(select ID, sum(value) as Total from data group by id) b
on
a.ID = b.id


- Jeff
Go to Top of Page
   

- Advertisement -