Query to calculate the percentage

C

cdolphin88

Hi,

I have a table with field physical damage (number) and this can be
either 0,1 or 2.

I need to calculate the percentage of occurrance for when is 1 and 2.

How should I do that? Can someone help me?

For example.

Physical Damage Percentage
0 0 0%

1 2 66.66%

2 1 33.33%


Cheers!

C
 
J

John Spencer

You didn't give much detail on your table structure. Calculating the
percentage for the entire table should look something liek

SELECT [Physical Damage]
, Count([Physical Damage])/(SELECT Count( [Physical Damage]) FROM
[YourTable]) as Percentage
FROM [YourTable]
GROUP BY [Physical Damage]
 
C

cdolphin88

I need to calculate the percentage for each "row", not the entire
table.
Let's say that I have 3 rows, I have 1 row with physical damage value =
2 and 2 rows with physical damage value = 1.

So the percentage for physical damage value = 2 should be
CountOfPhysicalDamageValue2/ Count(PhysicalDamage) ---> 66.66%

So the percentage for physical damage value = 1 should be
CountOfPhysicalDamageValue1/ Count(PhysicalDamage) ---> 33.33%

Cheers!

C


John Spencer escreveu:
You didn't give much detail on your table structure. Calculating the
percentage for the entire table should look something liek

SELECT [Physical Damage]
, Count([Physical Damage])/(SELECT Count( [Physical Damage]) FROM
[YourTable]) as Percentage
FROM [YourTable]
GROUP BY [Physical Damage]


Hi,

I have a table with field physical damage (number) and this can be
either 0,1 or 2.

I need to calculate the percentage of occurrance for when is 1 and 2.

How should I do that? Can someone help me?

For example.

Physical Damage Percentage
0 0 0%

1 2 66.66%

2 1 33.33%


Cheers!

C
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top