Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use EXISTS in BigQuery and acquire what matches the past log

I want to know. Has anyone who accessed today accessed in the past? The number of people.

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
  )

However, the BigQuery UI issues an error.

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

How can I refer to the same table by BigQuery?

thanks.

like image 325
Yamada JP Avatar asked Oct 24 '25 14:10

Yamada JP


1 Answers

Make sure to enable standard SQL first. For example,

#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
  );
like image 127
Elliott Brossard Avatar answered Oct 27 '25 01:10

Elliott Brossard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!