【发布时间】:2021-11-09 08:12:25
【问题描述】:
我应该使用 SQL,但不了解联合运算符的用法。 我的目标是为每个冰淇淋检索 3 列:ice_cream_id、ice_cream_name、manufacturer_name。这些应该根据 ice_cream_id 升序排列。因此,例如,如果我有普通香草冰淇淋,我不想与所有 3 家制造商一起识别,而只想识别第一。
我了解 SELECT 和 FROM 命令,但不了解 WHERE: SELECT ice_cream_id, ice_cream_name,manufacturer_name FROM ice_cream,manufacturer 中的联合运算符。
此外,我应该检索制造成本大于 1 的所有冰淇淋的 id、名称、制造成本和制造商名称。我认为我也应该使用 WHERE 吗?
manufacturer
manufacturer_id manufacturer_name country
--------------- ----------------- ----------
1 Ben & Jerry's Canada
2 4 Friends Finland
3 Gelatron Italy
ice_cream
ice_cream_id ice_cream_name manufacturer_id manufacturing_cost
------------ ---------------- --------------- ------------------
1 Plain Vanilla 1 1
2 Vegan Vanilla 2 0.89
3 Super Strawberry 2 1.44
4 Very plain 2 1.2
ingredient
ingredient_id ingredient_name kcal protein plant_based
------------- --------------- ---------- ---------- -----------
1 Cream 400 3 0
2 Coconut cream 230 2.3 1
3 Sugar 387 0 1
4 Vanilla extract 12 0 1
5 Strawberry 33 0.7 1
6 Dark chocolate 535 8 1
contains
ice_cream_id ingredient_id quantity
------------ ------------- ----------
1 1 70
1 3 27
1 4 3
2 2 74
2 3 21
2 4 5
3 1 60
3 3 10
3 5 30
4 2 95
4 4 5
【问题讨论】:
-
SELECT ... FROM t1 JOIN t2 ON t1.cx = t2.cy JOIN t3 ON t2.xv = t3.cw WHERE t1.ca = 123
标签: sql database join where-clause