Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WITH in BigQuery

Does BigQuery support the WITH clause? I don't like formatting too many subqueries.

For example:

WITH alias_1 AS (SELECT foo1 c FROM bar)
, alias_2 AS (SELECT foo2 c FROM bar a, alias_1 b WHERE b.c = a.c)
SELECT * FROM alias_2 a;
like image 594
cshin9 Avatar asked May 24 '16 20:05

cshin9


People also ask

What is with in BigQuery?

The WITH clause contains one or more common table expressions (CTEs). Each CTE binds the results of a subquery to a table name, which can be used elsewhere in the same query expression. The syntax is as follows: WITH cte[, ...] BigQuery does not materialize the results of non-recursive CTEs within the WITH clause.

How can I remove special characters from a string in BigQuery?

BigQuery RegExp: How to replace special characters To replace special characters, you can use regular expressions like this [^a-zA-Z0-9]+ and REGEXP_REPLACE function.

Is between inclusive in BigQuery?

BigQuery Between operatorDue to the inclusive nature of this operator, it includes both the beginning and ending values of the range. The values may be of any kind, including text, numeric, date data, etc. This operator can be used in conjunction with the SELECT, WHERE, INSERT, UPDATE, and DELETE statements.

What does coalesce do in BigQuery?

COALESCE. Returns the value of the first non-null expression. The remaining expressions are not evaluated. An input expression can be any type.


2 Answers

Recently introduced BigQuery Standard SQL does support WITH clause
See more about WITH clause

See also how to Enabling Standard SQL

like image 176
Mikhail Berlyant Avatar answered Sep 19 '22 12:09

Mikhail Berlyant


BigQery Standard SQL is supporting WITH clause. The syntax is as shown below

with table2 as (Select column1,column2 from table1)
    select column1 from table2
like image 33
HKE Avatar answered Sep 22 '22 12:09

HKE