I have the following table:
imovel
ano | id | item | valor
Records:
2000| 1 | 201 | null
2001| 1 | 211 | 10
2002| 1 | 202 | null
2000| 2 | 201 | null
2001| 2 | 221 | 17
2002| 2 | 211 | 14
2000| 3 | 201 | null
What I need and always return from each id only the last record filtered by the last year and the item to be filtered, the first 2 characters of the item refers to the same and the last character refers to the option of the item (ex: The query of item 201 should return 2 records referring to id 2 and 3. The id 1 should not be returned because its last item update was made in 2002 where item 20 is with option 2).