在 BigQuery 中使用“With”然后“Delete”
Using `With` then `Delete` in BigQuery
使用 BigQuery 我想删除 ID 在 Common Table Expression
或 with
中的行
所以这是我的查询:
WITH
redundant AS (
SELECT
id,
MAX(updated_at) AS updated_at,
COUNT(*) AS counter
FROM
t1
GROUP BY
id
HAVING
counter >= 2)
DELETE
FROM
t1
WHERE
id IN (redundant.id)
AND updated_at NOT IN (redundant.updated_at )
我预计这些行将被删除,但我收到了这条错误消息:
Syntax error: Expected "(" or keyword SELECT but got keyword DELETE at [13:1]
以下适用于 BigQuery 标准 SQL
#standardSQL
DELETE FROM `project.dataset.table` d
WHERE EXISTS (
WITH redundant AS (
SELECT id,
MAX(updated_at) AS updated_at,
COUNT(*) AS counter
FROM `project.dataset.table`
GROUP BY id
HAVING counter > 2
)
SELECT 1 FROM redundant
WHERE d.id = id AND d.updated_at != updated_at
)
使用 BigQuery 我想删除 ID 在 Common Table Expression
或 with
所以这是我的查询:
WITH
redundant AS (
SELECT
id,
MAX(updated_at) AS updated_at,
COUNT(*) AS counter
FROM
t1
GROUP BY
id
HAVING
counter >= 2)
DELETE
FROM
t1
WHERE
id IN (redundant.id)
AND updated_at NOT IN (redundant.updated_at )
我预计这些行将被删除,但我收到了这条错误消息:
Syntax error: Expected "(" or keyword SELECT but got keyword DELETE at [13:1]
以下适用于 BigQuery 标准 SQL
#standardSQL
DELETE FROM `project.dataset.table` d
WHERE EXISTS (
WITH redundant AS (
SELECT id,
MAX(updated_at) AS updated_at,
COUNT(*) AS counter
FROM `project.dataset.table`
GROUP BY id
HAVING counter > 2
)
SELECT 1 FROM redundant
WHERE d.id = id AND d.updated_at != updated_at
)