开发者

Android question about SQL Cursor and GROUP BY

开发者 https://www.devze.com 2023-01-26 13:54 出处:网络
I have a query that is making use of GROUP BY so that the results are grouped by a date column.My question is this:

I have a query that is making use of GROUP BY so that the results are grouped by a date column. My question is this:

When I move through the cursor to get the results of the query, how can I get the multiple items associated with each group into my vector? For example, I want to get BOTH "Item X" and "Item Y" for October 16, 2010. Currently, I get them each separately. Here is my code:

Vector<Event> v = new Vector<Event>();
Event e;

 detailCursor.moveToFirst();
 while (detailCursor.isAfterLast() == false) {
      e = new Event();
      e.setEventDate(detailCursor.getString(detailCursor
                .getColumnIndex("eventDate")));
      e.setItem(detailCursor.getString(detailCursor
                .getColu开发者_运维技巧mnIndex("Item")));

      v.add(e);

      detailCursor.moveToNext();
 }
detailCursor.close();

So, when I get the results from my Vector, I will get:

October 12, 2010 - Item X

October 12, 2010 - Item Y

and I want:

October 12, 2010 - Item X, Item Y

Yes, I do have to change my Vector to support multiple items, but hopefully you get what issue I'm facing...

Thanks!


If your data is provided by SQLite you need to change your query and use GROUP_CONCAT(col) in this case.

That will concat in one value all the subvalues for the same group.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号