没有适配器就无法使用具有 2 个链接表和 1 个聚合函数 (SUM) 的查询? (在列表视图中使用)
我需要使用 2 个链接表和 1 个聚合函数进行查询。 就我而言,查询工作正常,但似乎它不能与适配器一起使用(因为聚合函数)。
这是我获取查询的函数:
public Cursor recupererRecapParFichier(String argument) {
return db.rawQuery("SELECT transactions._id as idT, utilisateurs._id as idU, SUM(transactions.montantTransaction) as total , utilisateurs.nomUtilisateur as nomU FROM transactions " +
"JOIN utilisateurs ON utilisateurs._id=transactions.idUtilisateurTransaction " +
"WHERE transactions.idUtilisateurTransaction=" + argument + " GROUP BY utilisateurs.nomUtilisateur, transactions._id, utilisateurs._id"
, null); }
现在,我如何获取光标:
argument = Long.toString(listeFichiers.getSelectedItemId());
Cursor c = db.recupererRecapParFichier(argument);
startManagingCursor(c);
现在,我可以做什么来将数据放入我的 listView 中?我尝试使用适配器,但由于聚合函数而出现问题。
谢谢
I need to do a query with 2 linked tables and 1 aggregate function.
In my case, the query is working fine but it seems that it can't be used with an adapter (because of the aggregate function).
This is my function to get the query :
public Cursor recupererRecapParFichier(String argument) {
return db.rawQuery("SELECT transactions._id as idT, utilisateurs._id as idU, SUM(transactions.montantTransaction) as total , utilisateurs.nomUtilisateur as nomU FROM transactions " +
"JOIN utilisateurs ON utilisateurs._id=transactions.idUtilisateurTransaction " +
"WHERE transactions.idUtilisateurTransaction=" + argument + " GROUP BY utilisateurs.nomUtilisateur, transactions._id, utilisateurs._id"
, null); }
And now, how I get my cursor :
argument = Long.toString(listeFichiers.getSelectedItemId());
Cursor c = db.recupererRecapParFichier(argument);
startManagingCursor(c);
Now, what can I do to put the data in my listView ? I've tried to use an adapter but there is a problem because of the aggregate function.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的问题不是由于聚合函数 AFAICT 造成的。您的问题是结果集中没有名为
_ID
的列。您必须拥有一个才能使用CursorAdapter
。Your problem is not due to the aggregate function, AFAICT. Your problem is that you have no column in the result set named
_ID
. You must have one in order to work withCursorAdapter
.好吧,问题就是你说的!
Curso 必须有一个名为“_id”的列,即使它只是一个别名......
我的解决方案:
Ok, the problem was exactly what you've said !
Curso must have one column named "_id" even if it's just an alias...
My solution :