Do anybody know how to calculate percentage based on stored value eg If beer equals 3 votes and pizza equal 2 votes. how do i display the percentage of votes for beer and for pizza.
Assuming your table has two fields: Item and Votes.
select yt.Item, yt.Votes/t.TotalVotes
from YourTable yt
cross join
(
Select sum(Votes) as TotalVotes
From YourTable
) t
I think this will get you what you need. One caveat, if votes is an integer, you'll need to use a cast function to convert the Votes and TotalVotes to decimals.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.