【问题标题】:How do I get the ID column (& other columns) that do not have the same value in the city column?如何获取在 city 列中没有相同值的 ID 列(和其他列)?
【发布时间】:2021-12-15 03:43:15
【问题描述】:

假设我有这个:https://i.imgur.com/skAJi07.png

我希望查询的结果如下所示:https://i.imgur.com/3zJVLtX.png

有人可以帮我吗?基本上,我要做的就是不获取同一 id 的所有城市值都不是迈阿密的 id。

我已经尝试了几个 group by/have(sum) 并且还尝试了不存在的地方。但我无法得到我想要的答案。

在 BigQuery 中不存在的地方出现此错误:

不支持引用其他表的相关子查询,除非它们可以去相关,例如通过将它们转换为有效的 JOIN。

提前致谢!

【问题讨论】:

    标签: sql google-bigquery


    【解决方案1】:

    考虑以下方法

    select *
    from your_table
    where true 
    qualify count(*) over win != countif(city =  'Miami') over win
    window win as (partition by id)     
    

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

    这里count(*) over win != countif(city = 'Miami') over win直译为where all city values for the same id is NOT Miami

    【讨论】:

    • 很高兴它对你有用。也考虑投票赞成答案:o)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-25
    • 2021-11-16
    • 1970-01-01
    • 1970-01-01
    • 2020-10-24
    • 1970-01-01
    相关资源
    最近更新 更多