SQLite 求某列的和 SUM()
发布时间:2020-12-12 20:02:18 所属栏目:百科 来源:网络整理
导读:关键代码: 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 (curs
关键代码: 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())
/** * 根据年月(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; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |