本文主要是介绍SQLite 求某列的和 SUM(),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
关键代码: cursor = db.rawQuery("select sum(money) from money where user_id=? and kind_name=? and keep_date like ?"
,new String[]{userId,kindName,month_year+"%"});
取值: if (cursor.moveToFirst())
{
do
{
sum=cursor.getInt(0);
} while (cursor.moveToNext());
}
/*** 根据年月(or年)、用户ID、类型返回消费金额* @param userId* @param kindName* @return*/public int findSumOfKind(String userId,String kindName,String month_year,String year){int sum=0;int i=0;Cursor cursor = null ;db = helper.getWritableDatabase();if(month_year==null){i=1;}switch(i){case 0:cursor = db.rawQuery("select sum(money) from money where user_id=? and kind_name=? and keep_date like ?",new String[]{userId,kindName,month_year+"%"});break;case 1:cursor = db.rawQuery("select sum(money) from money where user_id=? and kind_name=? and keep_date like ?",new String[]{userId,kindName,year+"%"});break;}if (cursor!=null){if (cursor.moveToFirst()){do{sum=cursor.getInt(0);} while (cursor.moveToNext());}}return sum;}
这篇关于SQLite 求某列的和 SUM()的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!