Skip to content
Advertisement

JOINs not giving expected results in SQL

I have two tables Table F and Table D.

Table F gives details about Financial Transactions of an Account (Payment, Toll, Interest). Table D shows Delinquency Status (if user has not paid into account). It shows different Status Codes. 0, 1, 2, 11 (which mean different things).

My tables structures are as follows:

I am trying to run code to find the SUM of all payments made on an account AFTER the Account went into Status Code 11 (ToID)

My code:

The results I am getting are:

The results I would like are:

Advertisement

Answer

You’re problem is there are no matching results with your where criteria. I think you’re actually looking to use conditional aggregation. I’ve also used an outer join in case there’s no match:

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