您好我写了这个查询,但它给了我不正确的语法错误。我想尝试更新BizValue,如果BUSINESS_UNIT ='价值'然后将BizValue更新为1 ...
请帮忙
UPDATE products.products
SET BizValue = CASE BizValue
WHEN BUSINESS_UNIT='Optoelectronics' THEN 1
WHEN BUSINESS_UNIT='Hardware' THEN 2
ELSE null
END
答案 0 :(得分:8)
从BizValue
部分取出CASE
:
UPDATE products.products
SET BizValue = CASE
WHEN BUSINESS_UNIT='Optoelectronics' THEN 1
WHEN BUSINESS_UNIT='Hardware' THEN 2
ELSE null
END
或
UPDATE products.products
SET BizValue = CASE BUSINESS_UNIT
WHEN 'Optoelectronics' THEN 1
WHEN 'Hardware' THEN 2
ELSE null
END