I have the following code...
protected long getNumQueuedChunks(boolean distinctEntries) throws Exception {
SQLiteDatabase db = null;
try {
db = dbhelper.getReadableDatabase();
String whereClause = C_STATUS + " = ? AND " + C_NUM_FAILURES + " < ?";
String[] whereArgs = new String[] {STATUS_AWAITING_PROCESSING, 10};
long count = DatabaseUtils.queryNumEntries(db, QUEUE_TABLE_NAME, whereClause, whereArgs);
return count;
}
finally {
try {
db.close();
}
catch(Exception ignore) {
}
}
}
...which works fine if I want to return the total amount of rows that match the WHERE condition.
However, I would like to only count records that have distinct/unique combinations of data across these 3 columns: C_URI, C_BYTE_START_NUM and C_NUM_BYTES.
I know I could do something like...
String[] columns = {C_URI, C_BYTE_START_NUM, C_NUM_BYTES};
String whereClause = C_STATUS + " = ? AND " + C_NUM_FAILURES + " < ?";
String[] whereArgs = new String[] {STATUS_AWAITING_PROCESSING, "10"};
Cursor c = db.query(true, QUEUE_TABLE_NAME, columns, whereClause, whereArgs, null, null, null, null);
int count = c.getCount();
...but I am hoping there is a more efficient way to perform a distinct count in this situation??
Just to add clarity, if I have this data in my table...
C_URI | C_BYTE_START_NUM | C_NUM_BYTES
1.jpg | 0 | 1024
1.jpg | 1024 | 1999
2.jpg | 0 | 500
2.jpg | 0 | 500
...the result of the distinct count should be 3.
NB - I have seen a similar requirement described here (second answer) but that doesn't help me as I am wanting to do a distinct count across 3 columns rather than just one.