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
  • Show your table definition (CREATE TABLE statement). You probably fell victim to integer division. Commented Jun 19, 2022 at 22:25

1 Answer 1

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:

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.