Obtaining Percentage

# Thread: Obtaining Percentage

1. Junior Member
Join Date
Dec 1969
Posts
5

## Obtaining Percentage

I have a field that has 1,2, or 3 as a value. Is there an easy way to determine what percent have value 1, value 2, etc.. Other than just doing 100.00 * count / count for each value?

2. Senior Member
Join Date
Dec 1969
Posts
11,334

## Huh?

What&#039;s so hard about doing the 100 * count/count?<BR><BR>Is this SQL or ASP?

3. Junior Member
Join Date
Dec 1969
Posts
5

## RE: Huh?

Not hard, just seems like there is an easier way than:<BR><BR>Declare @cntTotal DECIMAL<BR>set @cntTotal = (select count(*) from surveyanswers)<BR><BR>select FLOOR((select count(*) from surveyanswers where ans1 = 1)/@cntTotal * 100.00) AS cntOne,<BR> FLOOR((select count(*) from surveyanswers where ans1 = 2)/@cntTotal * 100.00) AS cntTwo,<BR> FLOOR((select count(*) from surveyanswers where ans1 = 3)/@cntTotal * 100.00) AS cntThree<BR><BR><BR>

4. Senior Member
Join Date
Dec 1969
Posts
480

## try this

select Ans1, count(ans1) as ct from surveyanswers group by ans1 order by ans1<BR><BR>this will give you a count for each Ans1

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•