You should have mentioned which query was used, but try:
SELECT contrato, MAX(ano) AS 'max_ano' FROM c GROUP BY contrato;
or:
SELECT contrato, MAX(ano) AS 'max_ano' FROM c GROUP BY contrato ORDER BY max_ano DESC LIMIT 1;
Bank created with:
CREATE TABLE "c" (
"id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
"contrato" INTEGER NOT NULL,
"codigo" INTEGER NOT NULL,
"ano" INTEGER NOT NULL
);
INSERT INTO "c" VALUES(1,13,7800,2015);
INSERT INTO "c" VALUES(2,12,7800,2014);
INSERT INTO "c" VALUES(3,12,7800,2013);
INSERT INTO "c" VALUES(4,12,7801,2016);
INSERT INTO "c" VALUES(5,12,7801,2013);
INSERT INTO "c" VALUES(6,12,5102,2017);
Some tests:
sqlite> SELECT * FROM c;
1|13|7800|2015
2|12|7800|2014
3|12|7800|2013
4|12|7801|2016
5|12|7801|2013
6|12|5102|2017
sqlite> SELECT contrato, MAX(ano) AS 'max_ano' FROM c GROUP BY contrato;
12|2017
13|2015
sqlite> SELECT contrato, MAX(ano) AS 'max_ano' FROM c GROUP BY contrato ORDER BY max_ano DESC LIMIT 1;
12|2017
sqlite>