SQLite 求某列的和 SUM()

SQLite 求某列的和 SUM(),第1张

概述          关键代码:  cursor = db.rawQuery("select sum(money) from money where user_id=? and kind_name=? and keep_date like ?"                                                                ,new String[]{u

关键代码: 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()所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/1172387.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-02
下一篇 2022-06-02

发表评论

登录后才能评论

评论列表(0条)

保存