Calculate Percentage Between Two Columns In SQL Query As Another Column


Answer :

Try this:

SELECT availablePlaces, capacity,         ROUND(availablePlaces * 100.0 / capacity, 1) AS Percent FROM mytable 

You have to multiply by 100.0 instead of 100, so as to avoid integer division. Also, you have to use ROUND to round to the first decimal digit.

Demo here


Comments

Popular posts from this blog

Chemistry - Bond Angles In NH3 And NCl3

Are Regular VACUUM ANALYZE Still Recommended Under 9.1?

Can Feynman Diagrams Be Used To Represent Any Perturbation Theory?