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

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable