BigQuery subtract graphs of two tables?

In MySQL, I can do SELECT (SELECT COUNT(*) FROM table1) - (SELECT COUNT(*) FROM table2)to get the difference between the values โ€‹โ€‹between two tables. When I try to do it in BigQuery, I get: Subselect not allowed in SELECT clause. How to run such a query in BigQuery?

+4
source share
1 answer

Since subsamples are not supported inside the SELECT clause, I would use CROSS JOIN for this particular query:

SELECT a.c - b.c
FROM
  (SELECT COUNT(*) c FROM [publicdata:samples.natality]) a
CROSS JOIN
  (SELECT COUNT(*) c FROM [publicdata:samples.shakespeare]) b
+4
source

Source: https://habr.com/ru/post/1543923/


All Articles