【问题标题】:Perform Simple Group By in Google Big Query在 Google Big Query 中执行简单分组
【发布时间】:2021-04-22 05:13:22
【问题描述】:

我有一个关于谷歌大查询的最简单的查询,它一直返回一个错误

Grouping by expressions of type STRUCT is not allowed

我只是想从两个位置选择电子邮件列表,将它们合并到一个 cte 中,并计算 cte 中的频率以识别重复。

这应该很容易 - 我错过了什么??

with a as (select properties.email as email, 'loc1' as tag from `loc1.contacts`),

b as (select properties.email as email, 'loc2' as tag from `loc2.contacts`),

c as (
select * from a 
union all
select * from b
)

select email, count(email) from c group by 1
sample data:

email/tag
bob@email.com/loc1
bob@email.com/loc2

expected results:
email/count
bob@email.com/2

【问题讨论】:

  • 请提供样本数据和期望的结果。
  • 完成了——这是我能想到的最简单的分组——只是简单地计算了电子邮件在 cte 中出现的次数。我必须缺少某种类型的简单 bigquery 特定语法

标签: sql google-bigquery


【解决方案1】:

看起来我需要添加 .value 才能实际获取电子邮件字段的值,以下查询按预期工作

with a as (select properties.email.value as email, 'loc1' as tag from `loc1.contacts`),

b as (select properties.email.value as email, 'loc2' as tag from `loc2.contacts`),

c as (
select * from a 
union all
select * from b
)

select email, count(email) from c group by 1

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多