CASE WHEN "__" LIKE "__" ELSE "__" MySQL 错误

CASE WHEN "__" LIKE "__" ELSE "__" MySQL Error

我正在尝试通过 MySQL 标准化数据集中的活动命名约定。请看下面的代码;

SELECT 
`Campaign`
FROM 
`cost_per_platform`
case when `Campaign` like '%brand%' then 'Brand'
else 'Other' end

这是 运行 通过 DOMO.com MySQL 函数。我收到以下错误;

The database reported a syntax error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'case when Campaign like '%brand%' then 'Brand' else 'Other' end' at line 5

有人对修复有任何建议吗?谢谢您的帮助。

您想要 select 子句中的 case 表达式:

select
    campaign,
    case when campaign like '%brand%' then 'Brand' else 'Other' end as new_campaign
from cost_per_platform

这会将第二列添加到结果集中,称为 new_campaign,表示 "standardized" 值。

如果您想要 update 查询(即,将现有值替换为 "standardized" 值)

update cost_per_platform
set 
campaign = case when campaign like '%brand%' then 'Brand' else 'Other' end

SELECT 
if(`Campaign` like '%brand%', 'Brand', 'Other' ) as Campaign
FROM 
`cost_per_platform`

足以满足您的需求吗?

您的查询看起来像

SELECT 
  case when `Campaign` like '%brand%' then 'Brand'
  else 'Other' end
FROM 
`cost_per_platform`