vendredi 17 avril 2015

SUM sqlite column values in android

I must get the sum of the values of a column, but I get the number of the rows of the table.


Here is the code that I use to retrieve the sum value:



Cursor c=sqLite.getPrezzoTotaleCarrello();

while(c.moveToNext())
{
prezzoTotaleCarrello.setText(c.getString(c.getColumnIndex("Somma_totale")));
Log.d(prezzoTotaleCarrello.getText().toString(),"Visualizziamo");
}


Here is the code of the getPrezzoTotaleCarrello() method:



public Cursor getPrezzoTotaleCarrello()
{
String query = "select SUM(Prezzo_totale) AS Somma_totale from Carrello";

return getReadableDatabase().rawQuery(query, null);
}


The method getPrezzoTotaleCarrello is inside a class extending SQLiteOpenHelper.


Aucun commentaire:

Enregistrer un commentaire