Skip to content
Advertisement

Calculate percentage on an MySQL query

I have a query that returns some counts of data as follows, basically this table is posts and will contain either inbound or outbound posts. I want to make a query that will return the percentage of outbound posts.

e.g

This returns something like the following…

How would I modify the query above so it returns an additional column to calculate the outbound percent of the total, e.g (277 / 802) * 100 e.g (outbound / total) * 100)

So the expected output with the new column in the result would be as follows rounded off to the nearest whole number?

Advertisement

Answer

I think you can use simplest approach:

MySQL 8.0 fiddle

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement