【发布时间】:2020-05-20 21:58:14
【问题描述】:
现在,我首先运行以下查询:
select group_name, avg(numeric_field) as avg_value, count(group_name) as n from table_name group by group_name order by n desc;
假设我得到输出:
group_name | avg_value | n
----------------------------------------
nice_group_name| 1566.353 | 2034
other_group | 235.43 | 1390
.
.
.
然后,我将手动对每个组使用以下查询逐个删除每个组中的记录:
delete from table_name where group_name = 'nice_group_name' and numeric_field < 1567;
这里的 1567 是 avg_value 与 nice_group_name 的近似值。
如何自动对第一个查询结果的所有行运行第二个查询?
【问题讨论】: