0

To the alter column I want update values calculates from two another columns. I write:

UPDATE daily_eu SET total_cases_per_million = (total_cases/population)*1000000;

Result is for all records value:

0.000

How to fix to give correct result of my calculation?

1 Answers1

1

To avoid integer division (which truncates fractional digits):

UPDATE daily_eu
SET    total_cases_per_million = total_cases * 1000000.0 / population;

The numeric constant with a fractional digit (1000000.0) resolves to type numeric instead of integer, avoiding integer division. It's also typically more precise to multiply first.

Related:

Erwin Brandstetter
  • 605,456
  • 145
  • 1,078
  • 1,228