Reputation: 345
I need to get the row where the due_date field has the last month in every year. For eg: if I have 3 entries with due_date field like 2014-5-21,2014-6-21,2014-7-21 I need the last row in year 2014, that will be 2014-7-21, like wise in 2015 and the following years. Can someone help me out with this. I tried but nothing worked out
SELECT distinct(year(due_date)) FROM `vw_mortgage_repayment_schedule_org`
where mortgage_id ='AREM-1408614735-VLASFAQ8VI'
and month(due_date) = max(month())
I need all the last rows for the given mortgage of every year eg- 2014,2015,2016 etc
Upvotes: 0
Views: 22
Reputation: 4098
I think if you group by
the year of the due_date
, that might just about give you what you need, given that we search for the max
month in the select, and group by the year. Possibly. Can we have your table structure?
SELECT year(due_date), month(max(due_date)), max(due_date)
FROM `vw_mortgage_repayment_schedule_org`
where mortgage_id ='AREM-1408614735-VLASFAQ8VI'
GROUP BY year(due_date)
Upvotes: 1