MySQL 根据另一个 table 的可用性查询

MySQL query base on availibility of in another table

我是 MySQL 的新手,我需要一些帮助来构建简单的查询。我需要根据这一秒 table.

中的条件,从一个 table 链接到另一个 table 的“过滤”数据中获得一些结果

在名为“类别”的第一个 table 中,其中包含以下数据:

CategoryID CategoryName
1 food
2 drinks
3 sweets

在名为“product”的第二个table中有以下记录:

product CategoryID Quantity
apple 1 5
banana 1 0
vodka 2 0
beer 2 10
chocolate 3 0
biscuits 3 0

两个 table 都由 CategoryID 列链接。

我想构建一个查询 return 作为结果 只有 类别 / CategoryName/,该类别下有产品 数量>0.

预期结果是:

CategoryName
food
drinks

应该这样做:

SELECT
    DISTINCT categories.CategoryName
FROM
    categories
JOIN product ON product.CategoryID = categories.CategoryID
WHERE
    product.Quantity > 0;

SELECT categories.CategoryName 来自类别 在 product.CategoryID =categories.CategoryID 加入产品 其中 product.Quantity > 0;