【问题标题】:Bigquery - Sum Product of multiple value within two columnsBigquery - 两列内多个值的总和乘积
【发布时间】:2021-12-13 03:57:49
【问题描述】:

我有这个价值

我想计算一个新列,它将添加ticket_units_count和price的乘积,所以它必须是: 5 * 33104.0 + 4 * 23449.0 = 259316

如何在 bigquery 中做到这一点? 我试过这个

SELECT 
SUM(CAST(price AS FLOAT64) * CAST(ticket_units_count AS INT64))
FROM table

但它显示此错误:Bad double value: 33104.0;23449.0 需要您的帮助来指定查询以获得预期结果

【问题讨论】:

  • 请在您的问题中添加可读的示例数据。

标签: google-bigquery multiplication sumproduct


【解决方案1】:

考虑以下方法

select *, 
  ( select sum(cast(_count as int64) * cast(_price as float64))
    from unnest(split(ticket_units_count, ';')) _count with offset
    join unnest(split(price, ';')) _price with offset
    using (offset)
  ) as total
from your_table  

     

如果应用于您问题中的样本数据 - 输出是

【讨论】:

  • 它有效,请找到此代码进行复制:---- 输入 AS(选择“c”作为 id,“5;4”作为ticket_units_count,“33104.0;23449;0”作为价格) select *, ( select sum(cast(_count as int64) * cast(_price as float64)) from unnest(split(ticket_units_count, ';')) _count with offset join unnest(split(price, ';')) _price使用 (offset) ) 作为输入的总和
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多