Hay un error: ERROR: column "gana" does not exist LINE 25: WHERE n.idnota =gana ^