首页 > 其他分享 >How to use SUM and DINSTINCT with GreenDao?

How to use SUM and DINSTINCT with GreenDao?

时间:2023-11-16 13:34:14浏览次数:31  
标签:use sheet GreenDao share How popover post data se

How to use SUM and DINSTINCT with GreenDao querybuilder?

Ask Question Asked 7 years ago Modified 6 years, 7 months 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.

Share Edit   edited Nov 24, 2016 at 17:16     asked Nov 16, 2016 at 15:03 Naroju's user avatar Naroju 2,64744 gold badges2525 silver badges4545 bronze badges Add a comment

1 Answer

Reset to default 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.

Share Edit   answered Apr 10, 2017 at 17:44 javaxian's user avatar javaxian 1,82211 gold badge2121 silver badges2626 bronze badges Add a comment  

Your Answer

标签:use,sheet,GreenDao,share,How,popover,post,data,se
From: https://www.cnblogs.com/ioriwellings/p/17836011.html

相关文章

  • CTFshow Reverse 36D杯 BBBigEqSet wp
    用ida打开程序,一点点看汇编,发现似乎是机器生成的,先是输入0x80长的flag,然后有0x80段运算,运算的内容是每一个字符乘一个系数相加后与一个数比较。查看代码.text:0000000000001175pushrbp.text:0000000000001176movrbp,rsp.text:00......
  • 基于ABP的AppUser对象扩展
     在ABP中AppUser表的数据字段是有限的,现在有个场景是和老系统用户对接,需要在AppUser表中添加一个UId和IMId字段。本文以AppUser表扩展UId和IMId字段为例进行介绍。一.在Abp默认解决方案Test.Identity.EntityFrameworkCore更改IdentityEfCoreEntityExtensionMappings类,该操作......
  • chrome浏览器报Cannot read properties of undefined (reading 'getUserMedia')
    chrome访问摄像头的时候可能报这个错误。使用https协议可以解决这个问题,如果不能使用https可以通过修改chrome配制解决。在chrome地址栏输入chrome://flags/#unsafely-treat-insecure-origin-as-secure在Insecureoriginstreatedassecure的输入框输入要打开网页的地址如http......
  • umount 报错umount: /new_room: target is busy. (In some cases useful info
    挂载逻辑卷后,尝试更新逻辑卷的文件系统[root@serverlost+found]#umount/new_room/umount:/new_room:targetisbusy.(Insomecasesusefulinfoaboutprocessesthatusethedeviceisfoundbylsof(8)orfuser(1))报错说繁忙上网查发现我进入......
  • [938] How to operate with shapefiles using Geopandas
    GeopandasisaPythonlibrarythatmakesworkingwithgeospatialdataeasierbyextendingthedatamanipulationcapabilitiesofpandastospatialdata.Here'sabriefoverviewofhowtooperatewithshapefilesusingGeopandas:Installation:Makesure......
  • crontab任务以user用户执行hive -f命令不生效解决记录
    现象:创建了一个shell脚本任务,使用crontab进行任务调度,其中hive执行为: hive-f/opt/test.sql>/opt/test.log2>&1任务调度起来后一直报错提示: /usr/bin/hive:行3:/parcels/sbin/configure.sh:没有那个文件或目录 解决:1.使用hive绝对路径:首先保证user用户有启动hive的......
  • Mysql中如何解决You can't specify target table '表名' for update in FROM clause报
    Mysql中如何解决Youcan'tspecifytargettable'表名'forupdateinFROMclause报错为什么会出现这个错误呢?这是因为在MySQL使用时,在同一条SQL语句中,不允许先SELECT出同一个表的某些值,再对该表进行UPDATE操作。解决方式#WriteyourMySQLquerystatementbelowdeletef......
  • clickhouse的安装和配置
    使用虚拟机测试,系统为ubuntu22.04 一安装sudoapt-getinstall-yapt-transport-httpsca-certificatesdirmngrsudoapt-keyadv--keyserverhkp://keyserver.ubuntu.com:80--recv8919F6BD2B48D754echo"debhttps://packages.clickhouse.com/debstablemain"|su......
  • IPQ9574 vs IPQ9554|QCN9274vs QCN6274|WiFi 7Use Case
    IPQ9574vsIPQ9554vs QCN9274vsQCN6274 IndustrialApplications|WiFi7UseCaseAnticipatingtheFuture:ExploringPotentialUseCasesofWi-Fi7Astechnologycontinuestoevolveatarapidpace,theanticipationforthenextgenerationofwirelessconnecti......
  • husky——The '.husky/pre-commit' hook was ignored because it's not set as execut
    前言系统:machint:The'.husky/pre-commit'hookwasignoredbecauseit'snotsetasexecutable.hint:Youcandisablethiswarningwith`gitconfigadvice.ignoredHookfalse`.hint:The'.husky/prepare-commit-msg'hookwasignoredbec......