我的代码
select
(select ifnull(sum(registerAmount),0)
from register where register.orderID = orders.orderID) as theTotal
from orders
left join register on orders.orderID = register.orderID
where orders.customerID = 17 and invSent = true
显示8行... 5包含0而3则不包含。
如果我添加
group by orders.customerID
我得到一行包含零。
如何获得包含总数的一行?
答案 0 :(得分:0)
如果你只想要一行包含所有内容,只需做一个简单的INNER JOIN并选择总和。
SELECT IFNULL(SUM(registerAmount), 0) as theTotal
FROM orders
INNER JOIN register ON orders.orderID = register.orderID
WHERE orders.customerID = 17 and invSent = true