[英]Update column B to column A, but only If table A is empty
I need to move the values in the column name 我需要移动列名称中的值
options_2 options_2
into the column name 进入列名
options_1 options_1
But only on the condition when options_1 is empty . 但仅在options_1为空的情况下。 (Point A in the image.) If options_1 is not empty ( Point B in the image ), then nothing should happen as I do not want to overwrite the existing values. (图像中的A点。)如果options_1不为空(图像中的B点),则什么也不会发生,因为我不想覆盖现有值。
Additionally, I would like to then clear our options_2. 此外,我想清除我们的options_2。 But this time the rule should be to only clear our options_2 if it is the exact duplicate of options_1. 但是这次的规则应该是仅清除我们的options_2,如果它与options_1完全相同。 This would make sure that it won't delete all the option_2 values, which are valid ones further down in the database. 这样可以确保它不会删除所有option_2值,这些值在数据库中更远的地方都是有效的。
The structure is as follows: 结构如下:
database_name >> wp_cart66_products 数据库名称>> wp_cart66_products
I researched and found the command: 我研究并找到了命令:
update 'wp_cart66_products' set 'options_1' = 'options_2' 更新'wp_cart66_products'设置'options_1'='options_2'
But this has no conditional rules, and would transfer and overwrite valid values as well, which I do not want. 但这没有条件规则,并且会传输和覆盖有效值,而我不希望这样做。
update wp_cart66_products
set options_1 = options_2,
options_2 = ''
where options_1 IS NULL or options_1 = ''
This should do what you need. 这应该做您需要的。 Note that is goes ahead and clears options_2
when copying the data over, as in this case options 1 & 2 would have been equal if option 2 remained unchanged. 请注意,此操作将继续进行,并且在复制数据时会清除options_2
,因为在这种情况下,如果选项2保持不变,则选项1和2将相等。
UPDATE `wp_cart66_products`
SET
`options_1` = `options_2`,
`options_2` = ''
WHERE
`options_1` = ''
OR `options_1` IS NULL
This takes care of all your cases in Block A of your picture, but would not touch those items in Block B. This sounds like what you wanted. 这将处理您图片A块中的所有案件,但不会碰到B块中的那些项目。这听起来像您想要的。
You could then run a second query like this to take care of the cases where option_1 and option_2 match from the start, and you want to clear options_2. 然后,您可以运行第二个这样的查询,以解决option_1和option_2从一开始就匹配并且要清除options_2的情况。
UPDATE `wp_cart66_products`
SET `options_2` = ''
WHERE `options_1` = `options_2`
After your run these two queries you will only have two different cases for your field tuple: 运行这两个查询后,您的字段元组将只有两种不同的情况:
options_1
is non-zero-length string and options_2
is empty string options_1
是非零长度字符串,而options_2
是空字符串 options_1
and options_2
are non-matching strings of non-zero length. options_1
和options_2
是长度不为零的不匹配字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.