[英]SQL copy data from one column to another
在一個名為xt_products
的表中,有幾列。
我感興趣的是
products_ean
(varchar 128) 和products_model
(varchar 255)
如果products_model
中的條目超過 10 個字符,我想將值從products_model
復制到products_ean
。
例如products_model
的值為 '1-2-3' 然后不復制 如果products_model
的值為 '12345678910' 然后復制
謝謝安德烈亞斯
使用UPDATE
語句的WHERE
子句中的 function CHAR_LENGTH()
檢查products_model
中的字符數:
UPDATE xt_products
SET products_ean = products_model
WHERE CHAR_LENGTH(products_model) > 10
您可能還想在WHERE
子句中添加另一個條件:
AND CHAR_LENGTH(products_model) <= 128
因為products_ean
允許的最大長度是128
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.