历史记录,搜索历史记录等,这些记录又不能无限的存储,只需要记录最新的N条就可以。
bean对象
import com.lidroid.xutils.db.annotation.Column;
import com.lidroid.xutils.db.annotation.Id;
import com.lidroid.xutils.db.annotation.NoAutoIncrement;
import com.lidroid.xutils.db.annotation.Table;
import java.io.Serializable;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.extern.java.Log;
/**
* Created by xdjaxa on 2017/6/20.
*/
@Table(name = "sandbox_search_table")
@Data
@Log
@AllArgsConstructor
@NoArgsConstructor
public class SanBoxSerach implements Serializable{
@Id
@NoAutoIncrement
@Column(column = "_id")
private String id;
@Column(column = "pid")
@Getter
@Setter
private String pid;
@Column(column = "time")
@Getter
@Setter
private long time;
}
sql语句
String sql = "delete from sandbox_search_table where" +
" (select count(time) from sandbox_search_table )> 9 and " +
" time in (select time from sandbox_search_table order by time desc limit " +
" (select count(time) from sandbox_search_table) offset 9 )";