你好,我有三张mysql表,包括交易、其他贷款和付款。我想对load\u amount和additional from table transaction列求和,然后将其和other\u loan列amount相加,再减去payment table中payment\u amount列的和。下面是我的代码:
$result = $db->query("
SELECT *
, (sum(load_amount) + sum(additional) + sum(amount)) - sum(payment) as total
FROM transaction
, other_loan
, payment
INNER JOIN client
ON client.id=transaction.id
INNER JOIN other_loan
ON other_loan.id=transaction.id
INNER JOIN payment
ON payment.id=transaction.id
INNER GROUP
BY client.id
");
这是我的table:交易其他贷款付款
我正在表格中显示结果,并显示以下错误消息:
致命错误:未捕获错误:对布尔值上的成员函数fetch\u assoc()调用
请帮忙。谢谢您。
1条答案
按热度按时间j2qf4p5b1#
您的查询失败(因此
$result
是布尔型的false
)因为你有JOIN
ed表格other_loan
以及payment
两次(第一次使用隐式JOIN
操作员,
)不给他们取别名。我怀疑您实际上不想这样做,您的查询应该如下所示:我也怀疑
load_amount
实际上应该是loan_amount
.