我一直在尝试获取此查询的结果,以包含所有的flavor.model并对订购的数量进行求和。它确实有效,只是当没有订购任何东西时,它不会显示 flavor 表中的任何内容。我认为左连接会包含左侧的所有项目?
select
flavor.id,
flavor.model,
IFNULL(SUM(orders.quantity),0)as ORDERED
from
orders
LEFT JOIN
flavor
ON orders.model=flavor.model
where
orders.orddate >= '131006'
and orders.orddate <= '131013'
and orders.buyer<>'****@gmail.com'
GROUP BY
flavor.model
最佳答案
您可能想要使用 RIGHT JOIN
而不是 LEFT JOIN
作为左列,orders
是您的引用表,因此您不会获得未找到的 flavor
值。
关于mysql - 左连接?不返回零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19609733/