0

Is this the correct syntax? I am using the traditional method of (new/old)-1 to work out the % difference between yesterday's registrations and a week from yesterday's registrations. I am getting '0' which does not seem right...

select
sum(case when (timestampregistered::date = current_date - 1) then 1 else 0 end)
    / sum(case when timestampregistered::date = current_date - 8 then 1 else 0 end) - 1 as pct_diff
from customers_table
Dizz
  • 43
  • 6
  • Does this answer your question? [Division ( / ) not giving my answer in postgresql](https://stackoverflow.com/questions/34504497/division-not-giving-my-answer-in-postgresql) – forpas Jan 27 '22 at 18:08
  • ah yes thank you! – Dizz Jan 28 '22 at 08:51

1 Answers1

1

You are doing integer arithmetics, so your answers will be integers. Try

[...]then 1.0 else 0.0 end
Vesa Karjalainen
  • 1,087
  • 8
  • 15