我遇到了这个问题
SELECT
CASE WHEN QuantityPart =< Threshold
THEN (Threshold - QuantityPart) + Threshold
END as RecommendedReorderQuantity, *
FROM parts, stock
任何人都可以帮忙吗?
SELECT *,
CASE WHEN QuantityPart =< Threshold
THEN (Threshold - QuantityPart) + Threshold
END as RecommendedReorderQuantity
FROM parts INNER JOIN stock
ON parts.PartID = stock.PartID
答案 0 :(得分:3)
*
应该在CASE
sattement之前出现,还有一件事,应该是
<=
不 =<
SELECT *,
CASE WHEN QuantityPart <= Threshold
THEN (Threshold - QuantityPart) + Threshold
END as RecommendedReorderQuantity
FROM parts, stock
作为旁注,查询产生笛卡尔积。如果这不是你想要的,那么你需要提供链接条件,ex
SELECT *,
CASE WHEN QuantityPart <= Threshold
THEN (Threshold - QuantityPart) + Threshold
END as RecommendedReorderQuantity
FROM parts INNER JOIN stock
ON parts.columnName = stock.columnName
其中columnName
是定义其关系的列。
答案 1 :(得分:0)
此外,安全的做法是指定else条件,即使是微不足道的。
答案 2 :(得分:0)
替换=&lt;与&lt; =
选择 当QuantityPart&lt; =阈值时的情况 那么(门槛 - 数量部分)+门槛 END作为RecommendedReorderQuantity,* 从零件,库存