Skip to content
Advertisement

mathematical operation between two select statements

I’m currently trying to find the percentage of certain amount of preregistered users in my postgres db, the operation would be (1185 * 100) / 3104 = 38.17. To do that I’m using two select statements to retrieve each count, but I’ve been unable to operate between them:

This is what I have:

Thanks in advance for any hint or help.

Advertisement

Answer

you can use some with clause to simplifie your selects, substitute the values with your count(*) selects, maybe some formating to the result, and a check for 0 on value2

result : 38.17654639175258

with your selects:

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