'I'm trying to use either a sumif or case clause to sum up the values in a data set

I have the total amount expected to be saved, the total amount saved, the principal amount expected to be saved and the principal amount saved, now I'm trying to sum up the values of the principal saved if the total expected to be saved = to the total amount saved, I used the case clause sum (case when total_expected = total_saved then principal_saved end)

my issue is the then clause I'm linking it with a column that I don't think I should, the result is correct but I don't think the query is correct



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source