id | CUP | FREE
- | 2 | 0
- | 0 | 4
с выводом всей таблицы проблем нет :
Код: Выделить всё
public void onClick(View v){
switch (v.getId()){
case R.id.button:
Cursor c = sqdb.query("my_table",null,null,null,null,null,null);
if (c.moveToFirst()){
int idColIndex = c.getColumnIndex("id");
int cupColIndex = c.getColumnIndex("cup");
int frenchColIndex = c.getColumnIndex("free");
do{
Log.d("LOG_TAG", "ID = " + c.getInt(idColIndex) + ", CUP =" + c.getInt(cupColIndex) + ", FREE =" + c.getInt(frenchColIndex) );
} while (c.moveToNext());
}else
c.close();
break;
пытаюсь идти дальше и вывести суммы строк каждого столбца то есть значение CUP 2+0=2, FREE 0+4=4
и тут "прикра невдача спиткала радянських спортсменив"
Код: Выделить всё
case R.id.button1:
String your_query= "SELECT sum(CUP) as cup, sum(FREE)as free FROM my_table ";
Cursor result = sqdb.rawQuery(your_query, null);
if (result.moveToFirst()){
//int idColIndex = result.getColumnIndex("id");
int cupColIndex = result.getColumnIndex("cup");
int frenchColIndex = result.getColumnIndex("free");}
do{
Log.d("LOG_TAG", " CUP =" + result.getInt(cupColIndex) + ", FREE =" + result.getInt(frenchColIndex) );
} while (result.moveToNext());
}else
result.close();
break;
спс