如何在BigQuery中使用EXISTS并获取与过去日志匹配的内容

时间:2017-02-28 12:33:30

标签: google-bigquery

我想知道。今天访问过的人是否曾访问过?人数。

SELECT
  COUNT(user_id) AS repeater_user_count
FROM
  [access_log] AS table1
WHERE
  _PARTITIONTIME = TIMESTAMP('2017-02-28')
AND
  EXISTS
  (
    SELECT
      1
    FROM
      [access_log] AS table2
    WHERE
      _PARTITIONTIME BETWEEN TIMESTAMP('2017-01-31') AND TIMESTAMP('2017-02-27')
    AND
      table1.user_id = table2.user_id
  )

但是,BigQuery UI会发出错误。

Error: error at: 8.1 - 13.184. Only one query can be executed at a time.

如何通过BigQuery引用同一个表?

感谢。

2 个答案:

答案 0 :(得分:2)

首先确保enable standard SQL。例如,

#standardSQL
SELECT
  COUNT(user_id) AS repeater_user_count
FROM
  `access_log` AS table1
WHERE
  _PARTITIONTIME = '2017-02-28'
AND
  EXISTS
  (
    SELECT
      1
    FROM
      `access_log` AS table2
    WHERE
      _PARTITIONTIME BETWEEN '2017-01-31' AND '2017-02-27'
    AND
      table1.user_id = table2.user_id
  );

答案 1 :(得分:1)

考虑的另一个选择

  
<form method="get" action="http://www.clipartbest.com/cliparts/Kij/gGE/KijgGEgrT.png">
<button type="submit">Download!</button>
</form>