.
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order by anoPub desc) as tb group by anoPub desc' at line 7
error: select distinct anoPub from ( SELECT case when `lic_data_publicacao` = '0000-00-00 00:00:00' then extract(year from `lic_data`) when `lic_data_publicacao` <> '0000-00-00 00:00:00' then extract(year from `lic_data_publicacao`) end as anoPub FROM `licitacao` WHERE `agc` = order by anoPub desc) as tb group by anoPub desc