the example of group by in hibernate

本文介绍了使用Hibernate进行SQL分组查询的两个实例。第一个示例展示了如何按组织ID分组并统计用户数量;第二个示例说明了如何按职位ID和职位名称分组并计算应聘者数量。文中强调了在使用分组时正确指定列的重要性,避免因未列出所有非分组字段而导致的数据库错误。
the example of group by in hibernate

 StringBuffer sql = new StringBuffer("select count(user),org.id  from HrUsers user,OrgPerson person,OrgOupersonrelation relation,OrgOu org where user.id = person.id and person.id = relation.Pguid and relation.OuGuid = org.id group by org.id");

 

StringBuffer sql = new StringBuffer("SELECT position.id,position.positionName, COUNT(person) FROM HrAppliedperson person,HrPosition position WHERE person.AppPosition = position.id and  person.State!='已录用' AND person.State!='已放弃' AND person.State!='已报到' GROUP BY position.id,position.positionName");

 

note:after group by ,please add table.id, otherwise hibernate will create the statement that is select all column from .. where .. group by the column difined  by you, so the database will throw exception that describe as "some column must be after group by "
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值