Hello community!
I want to divide the sum of one column by the sum of another column when they are from different tables in SQL.
Practically, I want to divide this result:
SELECT "Tenant Name",
SUM(Amount)
FROM Receipts r
GROUP BY "Tenant Name"
HAVING Segment = "Market"
by
SELECT "Tenant Name",
SUM(Charge3)
FROM Charges r
GROUP BY "Tenant Name"
HAVING Segment = "Market"
But when I use JOIN to make the division, the result is not what I expected. For example, by running each query individually, I get that "Tenant A" Receipt amount (first query) is 2,350 and Charge amount (second query) is 2395, so, if I divide 2350 by 2395 the result is 0.9812 which is the result I expect, but it won't work if I do it in SQL in any way.
What am I doing wrong?
Thanks.