需要sqlite查询从具有最小值的表中删除行

时间:2009-03-26 06:52:56

标签: sql sqlite

如果记录数小于5,我希望t0从表中删除一个具有最小值的行;

1 个答案:

答案 0 :(得分:6)

您可以使用汇总mincount函数的子选择来执行此操作:

DELETE FROM the_table WHERE
  the_field = (SELECT min(the_field) FROM the_table)
  AND (SELECT count(*) FROM the_table) < 5;