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 ') as rk, count(chiave) as chiavi from ((strutture s left join strutture_search k' at line 1
select distinct s.*, sum(rank) as rk, count(chiave) as chiavi from ((strutture s left join strutture_search k on k.idstr = s.id) ) where s.attiva='S' and administrative_area_level_3 = 996 and ( chiave = 'ristorante') group by k.idstr order by chiavi desc, rk desc, crediti desc, data_mod desc limit 0, 16