在起草ORMlite(Android)请求时,真的需要您的帮助。
有sql查询(NamedQuery):
select m.contact.stringId, count(m.contact.stringId) from MessageEntityImpl m where m.status = MessageStatus.NEW group by m.contact.stringId"
SELECT m.chat_id, c.stringid, c.fullname, m.message, Max(posted) as postDate from messageentity m inner join (select chat_id, MAX(posted) max_posted from messageentity group by chat_id) max_posted_date ON m.chat_id = max_posted_date.chat_id and posted = max_posted_date.max_posted inner join contactentity c on c.ID = m.contact_id group by m.chat_id, c.stringid, c.fullname, m.message order by postDate desc
答案 0 :(得分:1)
最好发出一个原始查询以获得结果(如GenericRawResults<T>
),然后遍历容器以获得所需的结果。这是一个例子 -
String sql = "select m.contact.stringId from MessageEntityImpl m where m.status = MessageStatus.NEW group by m.contact.stringId";
ArrayList<String> id = new ArrayList<>();
try
{
GenericRawResults<String[]> grr = getDao().queryRaw(sql);
List<String[]> results = grr.getResults();
for (String[] outArray : results)
id.add (outArray[0]);
}
catch (SQLException sqle)
{
sqle.printStackTrace();
}
getDao()可以是BaseDaoImpl<T,ID>
。