Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
BigQuery SQL如果记录重复过多_Sql_If Statement_Google Bigquery - Fatal编程技术网

BigQuery SQL如果记录重复过多

BigQuery SQL如果记录重复过多,sql,if-statement,google-bigquery,Sql,If Statement,Google Bigquery,假设我有一个类似BigQuery文档中提到的模式: Last modified Schema Total Rows Total Bytes Expiration ----------------- ----------------------------------- ------------ ------------- ------------ 27 Sep 10:01:06 |- kind: string

假设我有一个类似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)
假设我们有全名:约翰,乔希,哈利

城市生活:纽约、芝加哥、西雅图

如何使用条件迭代CitiesLive和count。例如,我想计算一下有多少名全名为John的用户同时居住在CitiesLive.place=纽约和CitiesLive.place=芝加哥,但没有居住在CitiesLive.place=西雅图

谢谢,
John

您可以使用省略IF关键字。(这是未记录的,我将提交一个bug以确保它得到记录)

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