从数组中删除空/空值

时间:2018-09-11 15:56:14

标签: google-bigquery

我正在努力理解BigQuery中的数组和结构。当我在标准SQL中运行此查询时:

with t1 as (
  select 1 as id, [1,2] as orders
  union all
  select 2 as id, null as orders
)
select
  id,
  orders
from t1
order by 1

我在json中得到此结果:

[
  {
    "id": "1",
    "orders": [
      "1",
      "2"
    ]
  },
  {
    "id": "2",
    "orders": []
  }
]

我要删除以删除id = 2的订单值,以便获取:

[
  {
    "id": "1",
    "orders": [
      "1",
      "2"
    ]
  },
  {
    "id": "2"
  }
]

我该怎么做?我需要添加另一个CTE来删除空值吗?

0 个答案:

没有答案