我在这里有一个查询:
select * from warehouselog where productDescription is null;它返回给我以下内容:
ProductCode productDescription
PKFIL11014 null
PKOUT15012 null
PKLAB14016 null
PKLAB14005 null
PKPOL17024 null我知道有数据,这些产品代码和一些数据在同一个表中。
例如:
PKLAB14005 blue pen
PKPOL17024 black pen如何更新productDescription is null所在的表,并将productDescription设置为ProductCode中包含数据的值?它不需要是唯一的。
发布于 2020-05-26 22:39:06
使用相关子查询,指定为产品找到的最小值或最大值。选择MIN或MAX并不重要,两者都将查找非空值。下面是一个使用MIN的示例
update warehouselog w
set productdescription =
(
select min(productdescription)
from (select * from warehouselog) w2
where w2.productcode = w.productcode
)
where productdescription is null;(在MySQL中,from (select * from warehouselog) w2而不仅仅是from warehouselog w2是必需的,因为它不会将更新表直接用于子查询中。)
https://stackoverflow.com/questions/62024599
复制相似问题