我正在努力在Python中实现sqlite。这就是让我难堪的原因。你知道吗
给定以下数据结构:
id archiveSeconds archiveSize
-- -------------- -----------
13 1234567 100
34 1234568 100
13 1234568 100
24 1234570 100
。。。你知道吗
我想基于archiveSeconds删除除最近n条记录外的所有特定ID的记录,并保留所有其他记录不变。你知道吗
我能想到的最接近的事情是:
delete from Archives where id='13' not in (select id from Archives order by archiveSeconds desc limit 15);
但这会清空表中的所有记录。我想我需要嵌套几个select语句来实现这一点,但是我对完成这一点的sql语句感到迷茫。你知道吗
两个变化。首先,您不希望比较子查询中的
id
,而是希望比较时间。其次,要筛选给定id的子查询:我注意到一个表叫做
Archive
,另一个叫做Archives
。这是您最初的查询。你知道吗相关问题 更多 >
编程相关推荐