I have an income table as
title_id revenue cost
1 10 5
2 10 5
3 10 5
4 10 5
1 20 6
2 20 6
3 20 6
4 20 6
when i execute this request
SELECT SUM(revenue),SUM(cost)
FROM revenue
GROUP BY revenue.title_id
he produces the result
title_id revenue cost
1 30 11
2 30 11
3 30 11
4 30 11
which is fine, now I want to combine the final result with another table that has a structure like this
title_id interest
1 10
2 10
3 10
4 10
1 20
2 20
3 20
4 20
when I do a join with an aggregate function like this
SELECT SUM(revenue),SUM(cost),SUM(interest)
FROM revenue
LEFT JOIN fund ON revenue.title_id = fund.title_id
GROUP BY revenue.title_id,fund.title_id
he doubles the result
title_id revenue cost interest
1 60 22 60
2 60 22 60
3 60 22 60
4 60 22 60
I can’t understand why it is twice as much, please help
source
share