我需要在ORMLITE中使用max来检索ormlite表中的最新记录 select max(MODIFIED)FROM TABLE;
我想获得一个具有datemodified最大值的记录,其中userid是id; 对于特定用户ID,我想找到具有最大日期值的记录,即查找特定用户的最新条目
不能说,但我想你想知道如何MODIFIED使用ORMLite查询其字段等于最大值的某个对象.如果没有两个查询,我不确定你能在SQL中做到这一点.我认为你将不得不做一个原始查询来获取最大值然后再做另一个查询.
我在版本4.42中添加queryRawValue(...)了ORMLite,因此您可以执行以下操作:
long max = fooDao.queryRawValue(
"select max(modified) from foo where userid = ?", id);
// now perform a second query to get the max row
Foo foo = fooDao.queryBuilder().where().eq("modified", max).queryForFirst();
Run Code Online (Sandbox Code Playgroud)
手动你会做:
GenericRawResults<String[]> rawResults =
fooDao.queryRaw("select max(modified) from foo where userid = ?", id);
// there should be one result
long max = Long.parseLong(rawResults.getResults().get(0)[0]);
// now perform a second query to get the max row
Foo foo = fooDao.queryBuilder().where().eq("modified", max).queryForFirst();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3694 次 |
| 最近记录: |