示例,
SELECT * FROM stats_table
order by accuracy desc, totals desc;
这是按照精确度desc,总计desc
排序的并返回以下内容
id col_a amount col_b accuracy totals
881 stat_a 38.0 stat_b 71.60 162
884 stat_a 39.0 stat_b 70.52 173
109 stat_a 38.0 stat_b 69.91 105
880 stat_a 38.0 stat_b 69.88 249
883 stat_a 39.0 stat_b 69.47 262
如果准确性和总数都低于上面的行,我希望删除行,因此从示例中,应删除id 109作为准确性,并且总数都低于上面的行,ID 884
所以它应该像这样结束
id col_a amount col_b accuracy totals
881 stat_a 38.0 stat_b 71.60 162
884 stat_a 39.0 stat_b 70.52 173
880 stat_a 38.0 stat_b 69.88 249
883 stat_a 39.0 stat_b 69.47 262
理想情况下,因为有1000行,所以它应该遍历整个表。
请帮助
答案 0 :(得分:0)
要按照您描述的方式进行操作,您可以指定行号:
select *
from stats_table
where id in (
select a.id
from (SELECT *, row_number()over(order by accuracy desc, totals desc) as row FROM stats_table) a
inner join (SELECT *, row_number()over(order by accuracy desc, totals desc) as row FROM stats_table) b
on a.row = b.row + 1
and a.accuracy < b.accuracy
and a.total < b.total
)
然后你只需要将'select *'替换为'delete from',当你想要删除你想要删除的行时(由于显而易见的原因,我无法测试代码)。