shadi
shadi

Reputation: 441

use group by and having in android

how we can use group by and having in android? i want to use this query :

select sum(Quantity) from tbl1 group by name having id=lastid

and get result to use in other place of my project i saw in one page for groupy by use this code:

return mDd.query(DATABASE_TABLE,new String[] {
    KEY_ROWID,
    KEY_TITLE,
    KEY_DATAS,
    KEY_BODY,
    KEY_DATE_TIME
},null,null,KEY_TITLE,null,null);

but i don t know what should i do for having and sum()!!

Upvotes: 0

Views: 1340

Answers (1)

Snicolas
Snicolas

Reputation: 38168

You should use the rawQuery method of the SQliteDatabase class :

Cursor cursor = sqliteDatabase2.rawQuery(
    "select sum(Quantity) from tbl1 group by name having id=lastid", null);
if(cursor.moveToFirst()) {
    //process cursor
}

Inspired from Fetching a SQLite SUM in Java on Android

Upvotes: 1

Related Questions