Count number of times and item appears.

J

John

Please Help Desperate,

I have a Db with a table that holds the values 1,2,3,4,5 in muliple columns.
I need to be able count the number of times that each value occurs within a
column and have it return to me as percentage of the total number of values
returned.

If the values appear as
5
5
4
3
5
2
1
Then the number of 5 should appear as 42.87%
using 7/100=14.285 14.285*3=42.87

Thanks for all your help
 
M

MGFoster

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

SELECT NumberColumn,
Format(Count(*) / (SELECT Count(*) FROM table_name WHERE
....criteria...), "Percent") As Pct
FROM table_name
WHERE ...criteria...
GROUP BY NumberColumn

The Format() function just shows the result in percent format. You can
leave the number in its original format by removing the Format()
function & parameters.

The '...criteria...' will have to be the same in both the main query and
the subquery.

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQRPRNoechKqOuFEgEQK7nACdGlahsdAIqG4Jnb4Itbx5ZVu6KhkAn0i1
OkpClB/1sdPjktLslWZ+SVEw
=OqYk
-----END PGP SIGNATURE-----
 

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