我想检查2个数据库,以查看付款是否与总数相同。这是可能的,但是我得到的表很长:
select
transaction_id
,total_low+total_high a
, sum(money_received) b
from
archive_transaction inner join archive_transaction_payment
on archive_transaction.id=archive_transaction_payment.transaction_id
group by transaction_id;
实际上,我只想要总额错误的交易!! 因此,现在我想添加a!= b并给出无效的查询。如何进行? 表archive_transaction每笔交易有1行,但是archive_transaction_payment可以为一笔交易支付多笔款项。这对我来说很复杂。
select
transaction_id
,total_low+total_high a
, sum(money_received) b
from archive_transaction inner join archive_transaction_payment
on archive_transaction.id=archive_transaction_payment.transaction_id
where
a!=b
group by transaction_id;
答案 0 :(得分:0)
联接对于我仍然是有问题的,但是我找到了没有联接的答案,无法在数据库中查找错误。
SELECT id
FROM archive_transaction a
WHERE total_low + total_high != (SELECT Sum(money_received)
FROM archive_transaction_payment b
WHERE a.id = b.transaction_id);
现在,我在数据库中得到了一小段问题。感谢您的帮助。