Im having a mysql problem, I am trying to find the most current value for a specific month, the entire table schema and data can be seen here, the query that I have written to accomplish this is as follows:
max(case
when Month(py.pay_date) = 8
then amount end) previous_month_amount
However It is not returning the correct values, in this case the correct values should be:
name previous_month_amount
Carl 30
Mark 40
Hope I made the question clear enough, and thank you for your help.
I am interpreting your question as “What is the last payment made in each month?” If you answer this, then you can get the appropriate “last payment” just by choosing the right month. The following query does this: