0

I am trying to show the likelihood of dying if you contract COVID, by using a division expression as shown below but, I am only getting zeros for the results. I replaced the division symbol with a multiplication symbol and it worked but not with division symbol.

select location, date, total_cases, total_deaths, 
  (total_deaths/total_cases)*100 as DeathPercentage
from MyNewDB.CovidDeaths
order by location, date;

I expected to get a death percentage in the new column but all I am getting is zeros. I tried a similar expression in another database in SQLite Studio and it worked fine but not with this database.

Isolated
  • 5,169
  • 1
  • 6
  • 18
  • So all your data are pre-aggregated in your covidDeaths table? If that's the case, then what does the Date column represent? Showing sample data and expected output would be helpful. In case it's a display issue, perhaps try writing a simple CTE to ensure your formula works. Sidenote: Calculating a mortality rate at a Day level seems quite strict and perhaps misleading. A weekly or monthly rate may be considered. – Isolated Mar 22 '23 at 19:21
  • 1
    Probably that’s because of integer division, which SQLite does. See: https://stackoverflow.com/questions/8305613/converting-int-to-real-in-sqlite – GMB Mar 22 '23 at 19:24

0 Answers0