【问题标题】:Null for a decimal type of column BigQuery十进制类型的 BigQuery 列的 Null
【发布时间】:2022-01-22 18:35:12
【问题描述】:
   cast(sum(case
            when x.product = 'APPLE' and x.colour ='RED'then round(x.price1,2)

           when x.product <>  'APPLE' then **'NULL'**
           ELSE 0
         end) as decimal) as price,

price 列的类型为 decimal。但我只想在第二个 when 语句中输出 Null 而不是十进制值。

我该怎么做?

【问题讨论】:

  • select x.product, cast(sum(case when x.product = 'Apple' and x.colour ='RED'then round(x.price,2) when x.product ' Apple' 然后 NULL ELSE 0 end) as decimal) as price

标签: google-bigquery null decimal


【解决方案1】:

有简单的 NULL。它应该如下工作。

select cast(sum(case
when x.product = 'Apple' and x.colour ='RED'then round(x.price,2)



when x.product <> 'Apple' then NULL
ELSE 0
end) as decimal) as price

【讨论】:

  • 如果 x.product 'Apple',这会给我 0 作为输出。我想在输出中为 NULL
  • 谢谢。有效。还有另一个子表对同一列有一些逻辑。我也更新了你在那里提到的逻辑。
猜你喜欢
  • 1970-01-01
  • 2011-03-15
  • 1970-01-01
  • 1970-01-01
  • 2020-08-10
  • 1970-01-01
  • 2012-11-16
  • 2011-07-17
  • 2020-05-31
相关资源
最近更新 更多