Denne forespørgsel:
select sum(amount)
from aaa
where id not in (select id from bbb);
Fortolkes som:
select sum(aaa.amount)
from aaa
where aaa.id not in (select aaa.id from bbb);
fordi bbb.id
eksisterer ikke. Når du skriver SQL, foreslår jeg, at du altid bruger tabelaliaser. Forespørgslen, som du troede, du skrev:
select sum(aaa.amount)
from aaa
where aaa.id not in (select bbb.id from bbb);
ville generere den fejl, du forventer.