正在从 table 中删除最小值

Deleting min value from table

我有一个 table 的 10 分高分,当一个新用户带来一个比最低分更高的新高分时,我想从 table 中删除最低分。我已经尝试了所有建议的方法。请有人帮忙。

不要从 table 中删除 -- 涉及的维护工作太多。只是 运行 查询:

select t.*
from t
order by t.score desc
limit 10;

您可以在 (score) 上放置索引,这样 运行 会更快。

您可以将其封装在视图中。

像这样的东西应该有用。你会 运行 插入新记录后。

delete from t t1 where t1.score not in 
(select t2.score from t t2 order by t2.score desc limit 10)

如果table中的每条记录都有唯一的ID,那么我会修改如下:

delete from t t1 where t1.id not in 
(select t2.id from t t2 order by t2.score desc limit 10)