Skip to content
Advertisement

Unable to divide to counts of two separate lists in SQL, keeps returning 1

I have one list of events. One event name is creating an account and another is creating an account with Facebook. I am trying to see what percentage of accounts created use Facebook.

The code below will give me an accurate count of the number of facebook accounts and total accounts, but when I try to divide the two numbers it just gives me the number 1.

I am very new to SQL, and have spent hours trying to figure out why it is doing that to no avail.

I expect the output to be about ~.3, but the actual output is always exactly 1.

Advertisement

Answer

Conditional aggregation is a much simpler way to write the query. You appear to be using Postgres, so something like this:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement