skip to Main Content

I have a query where in I divide 2 columns and multiply it by 100 in a new column(DeathPercentage). But this new column data type is automatically set into bigint, is there a way that i could change it to decimal?

SELECT location, total_deaths, population.population, (total_deaths/population.population)*100 as DeathPercentage FROM covid_deaths
LEFT OUTER JOIN population
ON covid_deaths.location = population.country
WHERE covid_deaths.continent !='null'

enter image description here

3

Answers


  1. I don’t know if your language have this, but Java have something call casting. That might work for your language!

    Login or Signup to reply.
  2. Postgres has cast, 2 versions. In this case you can:

    (cast(total_deaths as numeric)/population.population)*100
                     OR
    (total_deaths::numeric/population.population)*100
    

    The first using the SQL standard and the second a Postgres extension.

    Login or Signup to reply.
  3. cast((total_deaths/population.population)*100) as numeric
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search