gpt4 book ai didi

mysql - 左连接?不返回零

转载 作者:行者123 更新时间:2023-11-30 01:08:32 25 4
gpt4 key购买 nike

我一直在尝试获取此查询的结果,以包含所有的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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com