| 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 "
|
the example of group by in hibernate
最新推荐文章于 2025-05-30 15:45:32 发布
本文介绍了使用Hibernate进行SQL分组查询的两个实例。第一个示例展示了如何按组织ID分组并统计用户数量;第二个示例说明了如何按职位ID和职位名称分组并计算应聘者数量。文中强调了在使用分组时正确指定列的重要性,避免因未列出所有非分组字段而导致的数据库错误。
1224

被折叠的 条评论
为什么被折叠?



