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