У меня есть одна таблица мобильных телефонов с колонками
- id
- имя_бренда
- имя_класса
- состояние
Пример таблицы:
id brand_name model_name condition sell_status
1 Apple 6s New unsold
2 Apple 6s Used unsold
3 Apple 6s New unsold
4 Apple 5s New sold
Я хочу, чтобы результат был похож на
brand_name model_name Quantity New Used
Apple 6s 3 2 1
Я пробовал это, но не получил результат «Новый» и «Использованный»:
public List<Mobile> getBrandMobileModel(String brand_name) {
List<Mobile> mobileData = new ArrayList<Mobile>();
String selectAllQuery = "SELECT brand_name, model_name, count(*), count(condition = ?), count(condition = ?) FROM " + Table_Mobile_Details + " WHERE brand_name = ? AND sell_status = ? GROUP BY model_name";
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(selectAllQuery, new String[]{"New", "Used", brand_name, "unsold"});
if (cursor.moveToFirst()) {
do {
Mobile mobile = new Mobile();
//mobile.setId(cursor.getInt(0));
mobile.setBrand_name(cursor.getString(1));
mobile.setModel_name(cursor.getString(2));
mobile.setQuantity(cursor.getString(3));
mobile.setCondition_new(cursor.getString(4));
mobile.setCondition_used(cursor.getString(5));
mobileData.add(mobile);
} while (cursor.moveToNext());
}
return mobileData;
}