Home > other >  Trying to calculate percentage but it is showing zero in every row
Trying to calculate percentage but it is showing zero in every row

Time:05-03

This is a screenshot of some data. I'm trying to calculate the DeathPercentage with the following script.

SELECT 
    location, date, total_cases,total_deaths, 
    ((total_deaths / total_cases) * 100) AS DeathPercentage
FROM 
    CovidDeaths_csv cdc

CodePudding user response:

total_deaths and total_cases are integers, and you are calculating the integer ratio. As deaths < cases, deaths/cases = 0. Try ((total_deaths*1.0/total_cases)*100).

  •  Tags:  
  • sql
  • Related