sql - SQL更新语句不更新,执行时无错误
问题描述
我每天安排以下两个更新语句来更新列(x_shippit_volumetric_weight),以较大者为准 - 净重或体积重量。 如果它已经存在并且正确,我在那里有 AND 语句来阻止它覆盖任何现有数据。
问题是,即使 x_shippit_volumetric_weight = 0,数据也没有更新?执行这两个更新语句时也没有显示错误。
任何关于它为什么不更新数据的帮助将不胜感激。
UPDATE stock_items
SET x_shippit_volumetric_weight = Round( ( stock_items.x_height * stock_items.x_width_cm * stock_items.x_length_cm ) / 4000, 4)
WHERE Round( ( stock_items.x_height * stock_items.x_width_cm * stock_items.x_length_cm ) / 4000, 4) > stock_items.weight
AND x_shippit_volumetric_weight <> Round( ( stock_items.x_height * stock_items.x_width_cm * stock_items.x_length_cm ) / 4000, 4)
AND (stock_items.x_height * stock_items.x_width_cm * stock_items.x_length_cm) <> 0;
UPDATE stock_items
SET stock_items.x_shippit_volumetric_weight = Round(( stock_items.weight ), 4)
WHERE stock_items.weight > Round( ( stock_items.x_height * stock_items.x_width_cm * stock_items.x_length_cm ) / 4000, 4)
AND stock_items.x_shippit_volumetric_weight <> Round(( stock_items.weight ), 4);
解决方案
好的,我发现了数据不更新的原因(在某些情况下)。只要 x_shippit_volumetric_weight 具有 NULL 值,它就不会更新。我实际上不明白为什么,但是在其他两个 UPDATE 语句之前添加以下 UPDATE 语句可以缓解这个问题。
UPDATE stock_items
SET x_shippit_volumetric_weight = 0
WHERE x_shippit_volumetric_weight IS NULL;
推荐阅读
- mysql - 在 mySQL 中使用 json_array 拆分数组中的 json 元素
- c# - Bind a WPF ComboBox Based on Data From Another ComboBox Using JSON in C#
- python - matplotlib 中日期时间轴的格式
- java - 检查包含整数值的列表时如何处理 HQL 查询中的空值
- sql - 无法在 impala 查询中同时使用 select distinct 和 group by
- ionic-framework - 如何从 Google Drive 下载 csv 文件以在移动应用中显示内容
- c# - 嵌套列表/循环依赖的不完整映射
- reactjs - React TypeScript:自定义钩子无限循环
- sql-server - 按层次顺序排序表
- ansible - 如何重命名一个ansible角色名称?