我见过很多有模棱两可的问题的案例,试过很多东西,还是不行
I have seen many cases with ambiguous problems and tried many stuff, still does not work
我想知道,为什么在这种情况下,它一直说Quantity column is ambiguous,有人可以帮忙吗?
SELECT SUM(AmountPaid),SUM(Quantity), ice_cream.IceCream
FROM ice_cream
INNER JOIN ice_cream_ingredient ON (ice_cream.IceCreamID =
ice_cream_ingredient.fkIceCreamID)
INNER JOIN ingredients ON (ice_cream_ingredient.fkIngredientID =
ingredients.IngredientID)
INNER JOIN sales ON (sales.fkIceCreamID =
ice_cream.IceCreamID)
WHERE IceCream='Vanilla Dream'
当查询中有多个 table 时,您应该始终 限定列名称。另外,学会使用table别名。
不清楚正确的限定名称是什么。这是一个猜测:
SELECT SUM(s.AmountPaid), SUM(s.Quantity), ic.IceCream
FROM ice_cream ic INNER JOIN
ice_cream_ingredient ici
ON ic.IceCreamID = ici.fkIceCreamID INNER JOIN
ingredients i
ON ici.fkIngredientID = i.IngredientID INNER JOIN
sales s
ON s.fkIceCreamID = ic.IceCreamID
WHERE ic.IceCream = 'Vanilla Dream';
我想知道,为什么在这种情况下,它一直说Quantity column is ambiguous,有人可以帮忙吗?
SELECT SUM(AmountPaid),SUM(Quantity), ice_cream.IceCream
FROM ice_cream
INNER JOIN ice_cream_ingredient ON (ice_cream.IceCreamID =
ice_cream_ingredient.fkIceCreamID)
INNER JOIN ingredients ON (ice_cream_ingredient.fkIngredientID =
ingredients.IngredientID)
INNER JOIN sales ON (sales.fkIceCreamID =
ice_cream.IceCreamID)
WHERE IceCream='Vanilla Dream'
当查询中有多个 table 时,您应该始终 限定列名称。另外,学会使用table别名。
不清楚正确的限定名称是什么。这是一个猜测:
SELECT SUM(s.AmountPaid), SUM(s.Quantity), ic.IceCream
FROM ice_cream ic INNER JOIN
ice_cream_ingredient ici
ON ic.IceCreamID = ici.fkIceCreamID INNER JOIN
ingredients i
ON ici.fkIngredientID = i.IngredientID INNER JOIN
sales s
ON s.fkIceCreamID = ic.IceCreamID
WHERE ic.IceCream = 'Vanilla Dream';