从 main table 中删除出现在 cte 中的记录

Delete from main table records that apear in cte

我有一个主 table,我需要从中删除在 CTE 中返回的行 最好我想做这样的事情:

with users_to_exclude as (
select uid, date, location_id
from some_previous_ctes_with_logic
)
delete from main_table mt
inner join 
users_to_exclude ux
 on ux.uid = mt.uid
 and ux.date = mt.date
 and ux.location_id = mt.location_id

但我不知道如何在 GBQ 中解决这个问题。 如果我只有一个要删除的键,那会更简单,因为我会在 where 子句中使用带有最后一个 select field 的所有 CTE。 但是 where (f1,f2,f3) in (select f1,f2,f3 from..) 在我的理解中在 GBQ 中是不可能的。

所以不确定该怎么做。

谢谢

考虑以下方法

delete from main_table mt
where exists (
  with users_to_exclude as (
    select uid, date, location_id
    from some_previous_ctes_with_logic
  )
  select 1 from users_to_exclude ux
  where ux.uid = mt.uid
  and ux.date = mt.date
  and ux.location_id = mt.location_id
);    

why do I have to attach it to the main table in the where clause?
If for some reason you want to go this direction - use below

delete from main_table mt
where (uid, date, location_id) in (
  with users_to_exclude as (
    select uid, date, location_id
    from some_previous_ctes_with_logic
  )
  select as struct  * from users_to_exclude
);