我想查询我的SQLite数据库并查询成本,即SQLite中的TEXT 但我想要列值的总和。
我该怎么做? 这是我的代码
public class estimate extends AppCompatActivity {
DatabaseHandler db;
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_estimate);
db=new DatabaseHandler(this);
tv=(TextView)findViewById(R.id.textView2);
tv.setText("joma="+getJoma()+"");
}
public double getJoma(){
Double sum=0.0;
SQLiteDatabase dt = db.getReadableDatabase();
Cursor res = dt.rawQuery("select cost from TB where type=জমা",null);
do{
sum =sum+ Double.parseDouble(res.getString(res.getColumnIndex("cost")));
}
while(res.moveToNext());
return sum;
}
}