仅在SQL数据库中保留前50条记录,并删除其余记录 [英] Leave only first 50 records in SQL database and delete the rest
本文介绍了仅在SQL数据库中保留前50条记录,并删除其余记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个分数表,该表由2个字段组成:名称和高分.像这样:
I have a table of scores, which is made of 2 fields: name and high score. Something like this:
-----------------------
| name | score |
-----------------------
| John | 2450 |
-----------------------
| Alice | 2420 |
-----------------------
... etc
我需要删除所有行,直到前50名得分.
I need to delete all the rows till the top 50 scores.
是否可以不创建另一个临时表?
Is it possible without creating another temporary table ?
推荐答案
请尝试一下
delete from scores_tbl Where
id not in
(select * from
(select id from scores_tbl order by score desc limit 50)
as temp)
这篇关于仅在SQL数据库中保留前50条记录,并删除其余记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文