S.M_Emamian S.M_Emamian - 22 days ago 6
Android Question

How to get sum of multiple count and price sqlite - android

I created a table like this :

id price count product_id

1 100 1 1
2 120 3 3
...


now I would like to get sum of all multiple
count
and
price
.

for this example :

(100 * 1) + (120 * 3) = 460

what I want is :
460


is it possible to use only the sql ?

Answer

Actually I have same issue. you can try using this Query

Cursor cur = db.rawQuery("SELECT SUM(count * price) FROM myTable", null);
if(cur.moveToFirst())
{
    return cur.getInt(0);
}

This was work for me.