【问题标题】:Count mixed fields in BigQuery计算 BigQuery 中的混合字段
【发布时间】:2021-05-18 23:26:44
【问题描述】:

我有两张表,其中包含下一列:

Tableproductscontains

  1. product_id [数字]
  2. 提供者 [数字]

orders 包含

  1. order_id [数字]
  2. cart_items(由多个 product_id 组成)例如: [{"product_id":304,"amount":250,"currency_rate":"1.28"},{"product_id":306,"amount":10,"currency_rate":"1.05"}]

问题:如何在 Google Big Query 中查询按 product_id 分组的某个提供商的已售 product_id(在 cart_items 中提到)?

【问题讨论】:

  • cart_items的数据类型是什么?

标签: sql google-bigquery


【解决方案1】:

你似乎有一个结构数组。所以,使用unnest()

select item.product_id, count(*)
from orders o cross join
     unnest(cart_items) item
group by 1;

【讨论】:

    猜你喜欢
    • 2016-09-14
    • 1970-01-01
    • 1970-01-01
    • 2013-11-06
    • 1970-01-01
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多