【问题标题】:error for varying types for CASE when updating cells更新单元格时 CASE 不同类型的错误
【发布时间】:2021-02-05 04:37:36
【问题描述】:

所以我尝试根据条件更新一些单元格,如果品牌名称是 robinhood,然后我们将产品设置为加密,我在 redshift 中尝试了下面的代码,但我得到了错误

ERROR:  CASE types character varying and boolean cannot be matched
select *,
case brand
when 'robinhood'
then business_unit_product::varchar = 'crypto'
else business_unit_product::varchar
end 
from tickets;

我应该改变什么?

【问题讨论】:

  • 不要使用SELECT,使用UPDATE来更新表数据。
  • @jarlh 我该怎么做?代码会是什么样子?

标签: sql amazon-redshift


【解决方案1】:

以下将brand 当前等于'robinhood' 的所有行的business_unit_product 更新为'crypto' (并且不对其他行进行任何更改)...

UPDATE
  tickets
SET
  business_unit_product = 'crypto'
WHERE
  brand = 'robinhood'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-03
    • 2023-04-01
    • 2011-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多