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

530 Valid Hostname Is Expected When Setting Up IIS 10 For Multiple Sites

C Perror Example

Converting A String To Int In Groovy