0

假设我有一个类似于 BigQuery 文档中提到的架构:

Last modified                 Schema                 Total Rows   Total Bytes   Expiration
 ----------------- ----------------------------------- ------------ ------------- ------------
  27 Sep 10:01:06   |- kind: string                     4            794
                    |- fullName: string (required)
                    |- age: integer
                    |- gender: string
                    +- phoneNumber: record
                    |  |- areaCode: integer
                    |  |- number: integer
                    +- children: record (repeated)
                    |  |- name: string
                    |  |- gender: string
                    |  |- age: integer
                    +- citiesLived: record (repeated)
                    |  |- place: string
                    |  +- yearsLived: integer (repeated)

假设我们有 fullNames : John, josh, harry

居住城市:纽约、芝加哥、西雅图

如何通过使用条件来遍历 cityLived 和计数。例如,我想计算有多少 fullName = John 的用户同时住在 cityLived.place = newyork 和 cityLived.place = Chicago,但没有住在 cityLived.place = seattle。

谢谢,约翰

4

1 回答 1

7

您可以使用 OMIT IF 关键字。(这是未记录的,我将提交一个错误以确保它被记录)

SELECT COUNT(*) FROM (
  SELECT fullname, 
    IF (citiesLived.place == 'newyork', 1, 0) as ny,
    IF (citiesLived.place == 'chicago', 1, 0) as chi
  FROM (FLATTEN(name_table, citiesLived))
  OMIT RECORD IF citiesLived.place = 'seattle') 
WHERE fullname = 'John' 
  AND ny == 1 
  AND chi == 1
于 2013-11-05T19:19:35.547 回答