问题描述
东城+崇文=东城,西城+宣武=西城,进行数据合并,不让改动原数据,所以只能改动程序原数据库:东城101,西城102,崇文103,宣武104....现数据库:东城101,西城102,崇文1013,宣武1024.....修改程序时去area的前3位group by,显示和统计下面的sql应该没问题select substr(this_.AREA,0,3) as y0_, this_.WORKTYPE as y1_, count(*) as y2_ from WINE.TBL_ARCHIVE this_ group by substr(this_.AREA,0,3), this_.WORKTYPEoracle的sql语句没问题,hibernate中原来的代码,下面的代码怎样修改DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TblArchive.class);.....ProjectionList projectionList1 = Projections.projectionList();projectionList1.add(Projections.groupProperty("area"));projectionList1.add(Projections.groupProperty("worktype"));projectionList1.add(Projections.rowCount());detachedCriteria.setProjection(projectionList1);问题是在hibernate 中怎么应用??哪位帮下,谢了。 问题补充:东城+崇文=东城,西城+宣武=西城,进行数据合并,不让改动原数据,所以只能改动程序原数据库:东城101,西城102,崇文103,宣武104....现数据库:东城101,西城102,崇文1013,宣武1024.....修改程序时去area的前3位group by,显示和统计下面的sql应该没问题select substr(this_.AREA,0,3) as y0_, this_.WORKTYPE as y1_, count(*) as y2_ from WINE.TBL_ARCHIVE this_ group by substr(this_.AREA,0,3), this_.WORKTYPEoracle的sql语句没问题,hibernate中原来的代码,下面的代码怎样修改DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TblArchive.class);.....ProjectionList projectionList1 = Projections.projectionList();projectionList1.add(Projections.groupProperty("area"));projectionList1.add(Projections.groupProperty("worktype"));projectionList1.add(Projections.rowCount());detachedCriteria.setProjection(projectionList1);问题是在hibernate 中怎么应用??哪位帮下,谢了。
解决方案
projectionList1.add(Projections.sqlGroupProjection("substr(area,0,3)", "substr(area,0,3)", null, null));
解决方案二:
引用您好,在问您一个问题,这个怎么解决列名无效的问题。首先你要用sqlGroupProjection,其实这里面写的要是数据库中的列名,不是实体的属性名。