I have a table in Sqlite database as follows:
JobId STRING,RigId STRING,area STRING,spares STRING,spare_id STRING
I want to get the count of the number of rows that have the same spare_id i.e if 4 rows have spare_id=2, then the count returned should be 4.
I have written the following query but I am not getting the proper count. Can anyone tell me why. My code is as follows:
public int get_report_entry_spare_count(String jobId,
String RigID) {
String countQuery="SELECT *, COUNT(*) AS spare_id FROM spare_replaced GROUP BY spare_id ";
SQLiteDatabase database = this.getWritableDatabase();
Cursor c = database.rawQuery(countQuery, null);
c.moveToFirst();
int total = c.getInt(0);
// int total = c.getCount();
c.close();
return total;
}
Aucun commentaire:
Enregistrer un commentaire