[英]Copy column to another column only if field is empty
I have an SQL question which may be basic to some but is confusing me. 我有一个SQL问题,对某些人来说可能是基本问题,但使我感到困惑。 Here is an example of a table: 这是一个表格示例:
buu_properties_products (price, years, area, covered_area)
Now I want to copy the area
column fields into the covered_area
fields but only if the covered_area
field is empty. 现在,我想将area
列字段复制到covered_area
字段中,但covered_area
是covered_area
字段为空。
I have almost 1000 products in this table and I need to update those column without deleting the covered_area values when they are present. 我在此表中有近1000种产品,当它们存在时,我需要更新这些列而不删除Covered_area值。
I am running MySQL 5.1 我正在运行MySQL 5.1
Depends what 'empty' means. 取决于“空”的含义。 If it means NULL
: 如果它表示NULL
:
UPDATE buu_properties_products
SET covered_area = area
WHERE covered_area IS NULL
If it means an empty string: 如果它表示一个空字符串:
UPDATE buu_properties_products
SET covered_area = area
WHERE covered_area = ''
If it means either: 如果这意味着:
UPDATE buu_properties_products
SET covered_area = area
WHERE covered_area IS NULL OR covered_area = ''
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.