不知道楼主是不是这个意思select B.id ,B.总额,c.总金额 from B,(select IDB,sum(金额) as 总金额 from A group by IDB) c where B.ID=c.IDB and B.总额<>c.总金额
好象没什么错误,你运行一下看看?