Android SQLite: Aggregierungsfunktion

  • Antworten:0
Wdmprojekt
  • Forum-Beiträge: 33

30.01.2011, 17:04:05 via Website

Die folgende Aggregierungsfunktion funktioniert über mein Firefox Plugin "SQLite Manager" nicht aber in meiner Android App:

SELECT COUNT(foo) AS mostfrequent,foo FROM apptable GROUP BY foo ORDER BY mostfrequent DESC LIMIT 1

Nun meine Frage, warum ist das so?

1// Get most frequent foo
2 Cursor myCursor = mDb.rawQuery("SELECT COUNT(foo) AS mostfrequent,foo FROM apptable GROUP BY foo ORDER BY mostfrequent DESC LIMIT 1", null);
3 if (myCursor != null) {
4 myCursor.moveToFirst();
5 }
6 int resultFoo = myCursor.getColumnIndexOrThrow(foo);
7 myCursor.close();
8 Log.d(TAG, "Haeufigste Foo: "+resultFoo);

Die DB Tabelle sieht so aus:

{ t.foo, t.bar, t.sonstige}

t.foo = {1,2,2,2,3,4}
t.bar = {1,2,3,4,5,6}
t.sonstige = {null,null,null,null,null,null}

Das Ergebnis von resultFoo sollte demnach 2 sein.

— geändert am 30.01.2011, 20:25:44

Antworten