android - How to find sum of field in a table using ORMlite -
model
public class householdincome implements serializable { private static final long serialversionuid = 1299751771198967848l; @databasefield(generatedid = true) private int id; @databasefield private string incomecategory; @databasefield(columnname = "date", datatype = datatype.date_string,format = "mm-dd-yyyy") private date date; @databasefield private int content; @databasefield private float sum; @databasefield(foreign = true,foreignautorefresh = true, canbenull = false, index = true) private category category; public householdincome() { } public int getid() { return id; } public void setid(int id) { this.id = id; } public int getcontent() { return content; } public void setcontent(int content) { this.content = content; } public float getsum() { return sum; } public void setsum(float sum) { this.sum = sum; } public string getincomecategory() { return incomecategory; } public void setincomecategory(string incomecategory) { this.incomecategory = incomecategory; } public category getcategory() { return category; } public void setcategory(category category) { this.category = category; } public date getdate() { return date; } public void setdate(date date) { this.date = date; }
}
database manager
public list<householdincome>getallhouseholdincome(date from,date to) { list<householdincome> householdincomes = new arraylist<householdincome>(); try { dao<householdincome, string> dahouseholdincom = dbhelper.getdaohouseholdincome(); final dateformat df = new simpledateformat("mm-dd-yyyy"); genericrawresults<householdincome> rowresults= dahouseholdincom.queryraw("select date,sum(sum) householdincome date between '01-01-2015' , '12-31-2015' group date", new rawrowmapper<householdincome>() { @override public householdincome maprow(string[] columnnames, string[] resultcolumns) { return new householdincome(df.parse(resultcolumns[0]), float.parsefloat(resultcolumns[1])); } }); rowresults.close(); } catch (sqlexception e) { logger.get().e(greenagriapp.getinstance(), e.getmessage()); e.printstacktrace(); } return householdincomes; }
the query returning empty result though while running manually in sqlite database browser returns results.
on debugging value size = 0 result shown.
could 1 please let me know have gone wrong ?
it might because u using condition , group on same column 'date'. try removing group clause first.
Comments
Post a Comment