关键代码: 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 ?",month_year+"%"}); break; case 1: cursor = db.rawquery("select sum(money) from money where user_ID=? and kind_name=? and keep_date like ?",year+"%"}); break; } if (cursor!=null) { if (cursor.movetoFirst()) { do { sum=cursor.getInt(0); } while (cursor.movetoNext()); } } return sum; }总结
以上是内存溢出为你收集整理的SQLite 求某列的和 SUM()全部内容,希望文章能够帮你解决SQLite 求某列的和 SUM()所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)