I have a table like this:
ID | Cost | Month | Year |
-------------------------------------
1081| 13000 | 5 | 2017 |
1081| 13500 | 9 | 2016 |
1081| 21000 | 2 | 2016 |
1229| 6500 | 7 | 2017 |
1229| 7800 | 5 | 2016 |
1312| 110000 | 8 | 2017 |
1312| 120000 | 5 | 2017 |
1312| 99000 | 5 | 2016 |
I've tried this:
select id, year, month, avg(cost) as Avg Cost
from price_history
group by id, year, month
order by id, year desc, month desc
How I can show the latest data like this:
ID | Cost | Month | Year |
-------------------------------------
1081| 13000 | 5 | 2017 |
1229| 6500 | 7 | 2017 |
1312| 110000 | 8 | 2017 |