BigQuery select 行在重复字段中有两个(或更多/更少)匹配项

BigQuery select rows with two (or more / less) matches in a repeated field

我的架构如下所示:

[
    {
        "name": "name",
        "type": "STRING",
        "mode": "REQUIRED"
    },
    {
        "name": "frm",
        "type": "RECORD",
        "mode": "REPEATED",
        "fields": [
            {
                "name": "c",
                "type": "STRING",
                "mode": "REQUIRED"
            },
            {
                "name": "n",
                "type": "STRING",
                "mode": "REQUIRED"
            }
        ]
    },
    {
        "name": "",
        "type": "STRING",
        "mode": "NULLABLE"
    }
]

示例记录如下所示:

frm 中有一行与 C = 'X' 匹配且另一行具有 C = 'Z' 时,我正在尝试编写 select 此行的查询。只有当两个条件都为真时,我才会喜欢 select 父行的“名称”。我实际上不知道如何实现这一目标。有什么建议吗?

例如这行得通,但我取消嵌套 frm 两次,我想一定有更有效的方法。

SELECT name FROM `t2`
WHERE 'X' in UNNEST(frm.c) AND 'Y' in UNNEST(frm.c)

考虑以下方法

select name
from your_table t
where 2 = (
  select count(distinct c)
  from t.frm
  where c in ('X', 'Z')
)