dis*_*ive 1 sql google-bigquery
WITH LAYER AS (
SELECT
SPLIT(de_nest, '|')[OFFSET(1)] AS product,
....
FROM `table`,
UNNEST(SPLIT(LOWER(REPLACE(variable, '^', '-')), '-')) AS de_nest
)
-- Filter out empty products
CREATE OR REPLACE TABLE `newtable` AS
SELECT * FROM LAYER WHERE product is NOT NULL
Run Code Online (Sandbox Code Playgroud)
这导致我出现以下错误。
Syntax error: Expected "(" or "," or keyword SELECT but got keyword CREATE at [25:1]
Run Code Online (Sandbox Code Playgroud)
但我似乎找不到解决这个问题的明智方法。我的第一个工作负载是取消第一个表的嵌套,第二个工作负载是对取消嵌套过程生成的那些列进行一些过滤。
您应该尝试将 CTE 声明放在CREATE语句后面:
CREATE OR REPLACE TABLE `new_table` AS
WITH layer AS ...
Run Code Online (Sandbox Code Playgroud)
编辑:一个完整的例子
CREATE OR REPLACE TABLE
`your_project.your_dataset.your_table` AS
WITH
layer1 AS (
SELECT
'this is my CTE' AS txt),
another_cte AS (
SELECT
txt,
SPLIT(txt, ' ') AS my_array
FROM
layer1)
SELECT
*
FROM
another_cte
Run Code Online (Sandbox Code Playgroud)
创建下表