【问题标题】:Apply lowercase in specific column for certain group of countries in BQ?在 BQ 中的某些国家/地区的特定列中应用小写?
【发布时间】:2022-07-05 22:16:58
【问题描述】:

对于 FR、ES 等国家/地区,我需要对 product_name 列应用小写,但对于其他国家/地区,CA、IL、DE 应该没有任何更改。我正在尝试使用此查询,但有些东西不起作用:

 SELECT
    id
    ,brand
    ,cern
    ,cern_3
    ,backpack
    ,qutoation
    ,product_name 
    ,CASE WHEN country_code in ('FR', 'ES') then lower(product_name) end
    ,category
    ,country_code
    ,timestamp
FROM table.name

【问题讨论】:

  • 你错过了 ELSE 部分:CASE WHEN country_code in ('FR', 'ES') then lower(product_name) ELSE product_name end
  • 这条评论不应该作为答案吗?

标签: sql google-bigquery


【解决方案1】:

对于其他国家/地区,您的查询可能返回null,因此@forpas 建议在comments 中添加else

CASE WHEN country_code in ('FR', 'ES') then lower(product_name) else product_name end

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多