【问题标题】:delete data based on sum of values根据值的总和删除数据
【发布时间】:2022-01-22 20:23:45
【问题描述】:

您好我想问一下是否可以根据大查询中的总和删除一些数据。 这是我只想删除总和超过 100 的行的问题。我尝试使用:

DELETE FROM (SELECT user, sum(paid) as money FROM test) where money > 100 

但它不起作用然后我尝试使用:

with table2 as (SELECT a.*, sum(paid) as money from `test` a)
DELETE from table2 where table2.money > 100 

它也没有工作

id login paid
1 john 99
1 john 2
2 josh 50
3 mark 800

结果应该只有 1 行。

【问题讨论】:

    标签: sql google-bigquery


    【解决方案1】:

    尝试使用以下 SQL 从 test 中删除 sum(paid) > 100 的数据。 执行后,对 test 表执行 select 以查看结果。

    delete from `test` 
    where id in (select distinct id 
                 from `test` 
                 group by id
                 having sum(paid) > 100)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多