XSLT存档  

不及格的程序员-八神

 查看分类:  ASP.NET XML/XSLT JavaScripT   我的MSN空间Blog
Asked 7 years ago
Viewed 1k times
 Part of Mobile Development Collective
2

I want to get the sum of total rows in a column of a table in SqlLite Database. I am using GreenDao Library. I know I Have to use SUM. But I don't know how to use it with GreenDao queryBuilder. Can anybody help me? and also DISTINCT.

 

1 Answer

2
 

This is how I did it. Assume there is the Company entity and it has the numOfEmployees field:

Cursor cursor = daoSession.getDatabase().rawQuery("SELECT SUM(" + Company Dao.Properties.NumOfEmployees.columnName + ") FROM " + Company Dao.TABLENAME, new String []{});
cursor.moveToFirst();
long result = cursor.getLong(0);

Note that you could hardcode the column and table names above, but this is way cleaner.

 
 

Your Answer

posted on 2023-11-16 13:27  不及格的程序员-八神  阅读(7)  评论(0编辑  收藏  举报