I have sample data
ID Name Amount cal_amt Run_amt Dates
1 Test 15000 0.00 15000 2020-06-01
1 Test 15000 0.00 30000 2020-04-01
1 Test 15000 12000 30000 2020-05-01
2 Test_1 18000 0.00 25000 2020-06-01
2 Test_1 18000 0.00 35000 2020-04-01
2 Test_1 18000 16000 35000 2020-05-01
I need to get MAX(month) of Run_Amount i.e : 2020-06-01 --> 15000
Need to fetch cal_amt of current month i.e : 2020-05-01 --> 12000 and 0.00 also relates to this month 2020-04-01
I need to get output like this :
ID Name Amount cal_amt Run_amt
1 Test 15000 12000 15000
2 Test_1 18000 16000 25000
It is sample data but have another few more columns are there I have tried with MAX() conditions and
ROW_NUMBER()over (PARTITION BY run_amt order by Date )
Can anyone suggest me the best way
Run_amtfrom the latestDate, and the value ofcal_amtfrom the current month, but what about the values forID,NameandAmount? where should they come from?ID,NameandAmountvalues...