删除多个已联接表Bigquery

时间:2019-02-13 12:49:00

标签: sql google-bigquery

我正在尝试在bigquery中一次delete来自多个表的行以清理数据库以进行进一步的分析。

我尝试过以下操作:http://www.mysqltutorial.org/mysql-delete-join/

    DELETE `test.TestLm.devc` T1, `test.TestLm.deva` T2
    FROM T1
    INNER JOIN T2 ON T1.id = T2.user_id
    WHERE is_bot IS TRUE

但是我得到了:

  

语法错误:[1:40]处出现意外的“,”

任何想法如何解决 Bigquery 上的问题?

UPDATE:

这是我的完整问题,要删除7个表。是否有可能在1个查询中或更快捷地执行此操作?

## 1-2 minutes :  ##
DELETE `test.TestLm.message_all` t1
WHERE relation_id IN 
(SELECT a.relation_id FROM `test.TestLm.relation_big` a 
    INNER JOIN `test.TestLm.users_big` b ON a.initier_id = b.id
    INNER JOIN `test.TestLm.users_big` c ON a.receiver_id = c.id
    WHERE (b.is_bot IS TRUE OR c.is_bot IS TRUE));

## 4+ minutes -- WARNING : WAIT UNTIL THE PREVIOUS QUERY ON 'message_all' IS FINISHED BECAUSE OF THE ABOVE JOINTURE ##
## ##
DELETE `test.TestLm.relation_big`
WHERE initier_id IN (SELECT id FROM `test.TestLm.users_big` WHERE is_bot IS TRUE)
OR receiver_id IN (SELECT id FROM `test.TestLm.users_big` WHERE is_bot IS TRUE);

## quicker queries - no need to wait ##
DELETE `test.TestLm.moderation`
WHERE user_id IN (SELECT id FROM `test.TestLm.users_big` WHERE is_bot IS TRUE);


DELETE `test.TestLm.report`
WHERE reporter_id IN (SELECT id FROM `test.TestLm.users_big` WHERE is_bot IS TRUE)
OR culprit_id IN (SELECT id FROM `test.TestLm.users_big` WHERE is_bot IS TRUE);

DELETE `test.TestLm.purchase_agg`
WHERE user_id IN (SELECT id FROM `test.TestLm.users_big` WHERE is_bot IS TRUE);

DELETE `test.TestLm.leads`
WHERE user_id IN (SELECT id FROM `test.TestLm.users_big` WHERE is_bot IS TRUE);

DELETE `test.TestLm.device`
WHERE user_id IN (SELECT id FROM `test.TestLm.users_big` WHERE is_bot IS TRUE);

## WARNING : !!!! WAIT UNTIL ALL PREVIOUS QUERIES ARE DONE !!!!! ##
DELETE FROM `test.TestLm.users_big` WHERE 
is_bot IS TRUE

1 个答案:

答案 0 :(得分:0)

在下面的标准sql模式下可以使用

DELETE test.TestLm.devc i
WHERE i.id IN (select id from test.TestLm.deva where id is not null)