Discussion:
percentage in sql query
(too old to reply)
Dave
2007-04-20 14:46:13 UTC
Permalink
I have a table of score which are 1's and 0's.

How would I go about writing a query to get the percentage of 1's against
the toal number of records?

Many thanks
strawberry
2007-04-20 15:20:24 UTC
Permalink
Post by Dave
I have a table of score which are 1's and 0's.
How would I go about writing a query to get the percentage of 1's against
the toal number of records?
Many thanks
SELECT (SUM( score ) / COUNT( score )) *100 percentage FROM `scores`
Dave
2007-04-20 16:01:36 UTC
Permalink
Feel a bit of a fool now, you always make it look so simple!

Many thanks, that's perfect
Post by strawberry
Post by Dave
I have a table of score which are 1's and 0's.
How would I go about writing a query to get the percentage of 1's against
the toal number of records?
Many thanks
SELECT (SUM( score ) / COUNT( score )) *100 percentage FROM `scores`
Continue reading on narkive:
Loading...