SQL 更新空表值
我正在使用两个表,表一是part_order
ONum PNum NumOrdered QuotPrice
2236 BZ66 1
2236 AZ52 10 29.90
2237 CA14 3
2240 CB03 1
,表二是part,看起来
PNum Description OnHand Warehouse UnitPrice
AZ52 Skates 20 2 36.95
BZ66 Washer 5 1 465.50
CA14 Skillet 13 1 28.99
CB03 Bike 44 3 195.50
我正在尝试用unitprice 值更新我的quotprice 列(如果它为空)。这意味着 29.90 应保留,但其他应更新。
我输入:
update part_order
set quotprice = (select part.unitprice
from part
where part.pnum = part_order.pnum
and quotprice is null);
除了切换值之外它还可以工作。我的 29.90 变成 null,其他 3 个值被更新。如果我再次输入,其他 3 个值将返回 null,而第二个值将填充 36.95。我想知道为什么它会更改值而不是仅检查空值。
I am working with two tables, table one is part_order looks like
ONum PNum NumOrdered QuotPrice
2236 BZ66 1
2236 AZ52 10 29.90
2237 CA14 3
2240 CB03 1
and table two is part and looks like
PNum Description OnHand Warehouse UnitPrice
AZ52 Skates 20 2 36.95
BZ66 Washer 5 1 465.50
CA14 Skillet 13 1 28.99
CB03 Bike 44 3 195.50
I'm attempting to update my quotprice column with unitprice values, if it is null. Meaning the 29.90 should stay but the others should be updated.
I type in:
update part_order
set quotprice = (select part.unitprice
from part
where part.pnum = part_order.pnum
and quotprice is null);
And it works aside from it switches the values. My 29.90 turns to null, and the other 3 values are updated. If I type it again, the other 3 values go back to null and the 2nd value is filled with 36.95. I am wondering why it changes the values instead of only checking for the null values.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)