Answer the question
In order to leave comments, you need to log in
How to calculate percentage of total mysql records?
Table Addresses (id_address,region,status)
SELECT count(*),addresses.region FROM addresses GROUP BY region - I count the total number of addresses by region as this query.
How to calculate in one request how many percent of these addresses have status = 5?
as a result, something like this
Region ---- 10,000 addresses --- 90% status 5
Answer the question
In order to leave comments, you need to log in
SELECT COUNT(*)/(SELECT COUNT(*) FROM addresses)*100 AS percent FROM addresses WHERE status=5
Usually I would pull out the data of the total number of values in the table and then all with status = 5
And in php I would calculate the ratio.
I think nested queries can help you.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question