起初我想通过导入csv文件来更新表格(产品价格),但我不认为这是可能的。
所以我创建了一个临时表并导入了2列:products_id,products_price
我觉得尝试运行这个sql:
UPDATE products p SET p.products_price=(
SELECT t.products_price
FROM temp_table t
WHERE t.products_id=p.products_id
)
这更新了所有与products_id匹配的价格,但也将所有其他产品设置为0.00
如果匹配并忽略其他product_ids,我该怎么办才能更新?
答案 0 :(得分:0)
您可以使用像
这样的更新联接查询UPDATE products p
JOIN temp_table t ON t.products_id=p.products_id
SET p.products_price = t.products_price;
答案 1 :(得分:0)
你可以使用内连接
from p in PartRevisions
let last_avg = 100* ( (p.AvgCost > p.LastCost) ?
((p.LastCost > 0) ? (p.AvgCost - p.LastCost) / p.LastCost : (decimal?)null):
((p.AvgCost> 0) ? (p.LastCost - p.AvgCost ) / p.AvgCost : (decimal?)null))
where (p.ImrInactive == 0)
where (p.LastCost != p.AvgCost) || (p.LastCost != p.ImrStandardMaterialCost)
where (last_avg > 10) || (last_avg == null)
orderby last_avg descending
select new {
PartID = p.ImrPartID,
Desc = p.ImrShortDescription,
AvgCost = p.AvgCost,
LastCost = p.LastCost,
Last_Avg = last_avg
}