欢迎投稿

今日深度:

SQLite 求某列的和 SUM(),sqlitesum

SQLite 求某列的和 SUM(),sqlitesum


 

 

      关键代码:  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;
	}


 

www.htsjk.Com true http://www.htsjk.com/SQLite/32456.html NewsArticle SQLite 求某列的和 SUM(),sqlitesum           关键代码:  cursor = db.rawQuery("select sum(money) from money where user_id=? and kind_name=? and keep_date like ?"                             ...
相关文章
    暂无相关文章
评论暂时关闭