SQL sum() 和 groupby 在休眠中怎么写?
How write SQL sum() and groupby in hibernate?
我的查询是:
select GRN_NO, IDENTIFICATION_NO, RBI_TRN_DATE, PERIOD_FROM, PERIOD_TO,
SUM(AMOUNT) AS AMOUNT
from PTAX_ECHALLAN_DATA
where IDENTIFICATION_NO in ('ECC0013056', '192009028150', '20150086699')
GROUP BY GRN_NO;
我正在尝试使用此代码:
Criteria cr = session.createCriteria(PTAX_ECHALLAN_DATA.class);
cr.setProjection(Projections.projectionList()
.add(Projections.sum("amount").as("amount"))
.add(Projections.property("rbiTrnDate").as("rbiTrnDate"))
.add(Projections.property("idNo").as("idNo"))
.add(Projections.property("grnDate").as("grnDate"))
.add(Projections.property("preiodTo").as("preiodTo"))
.add(Projections.property("preiodFrm").as("preiodFrm"))
.add(Projections.groupProperty("id.grnNO")));
cr.add(Restrictions.in("idNo", Arrays.asList(OldEc, EC, applnNo)));
cr.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
List list = cr.list();
但是报错。
The error is :"Caused by: java.sql.SQLSyntaxErrorException: ORA-00979:
not a GROUP BY expression".
这个怎么写?请帮忙。提前致谢。
您需要select除聚合列外的所有其他列分组依据
select GRN_NO, IDENTIFICATION_NO, RBI_TRN_DATE, PERIOD_FROM, PERIOD_TO,
SUM(AMOUNT) AS AMOUNT
from PTAX_ECHALLAN_DATA
where IDENTIFICATION_NO in ('ECC0013056', '192009028150', '20150086699')
GROUP BY GRN_NO, IDENTIFICATION_NO, RBI_TRN_DATE, PERIOD_FROM, PERIOD_TO
我的查询是:
select GRN_NO, IDENTIFICATION_NO, RBI_TRN_DATE, PERIOD_FROM, PERIOD_TO,
SUM(AMOUNT) AS AMOUNT
from PTAX_ECHALLAN_DATA
where IDENTIFICATION_NO in ('ECC0013056', '192009028150', '20150086699')
GROUP BY GRN_NO;
我正在尝试使用此代码:
Criteria cr = session.createCriteria(PTAX_ECHALLAN_DATA.class);
cr.setProjection(Projections.projectionList()
.add(Projections.sum("amount").as("amount"))
.add(Projections.property("rbiTrnDate").as("rbiTrnDate"))
.add(Projections.property("idNo").as("idNo"))
.add(Projections.property("grnDate").as("grnDate"))
.add(Projections.property("preiodTo").as("preiodTo"))
.add(Projections.property("preiodFrm").as("preiodFrm"))
.add(Projections.groupProperty("id.grnNO")));
cr.add(Restrictions.in("idNo", Arrays.asList(OldEc, EC, applnNo)));
cr.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
List list = cr.list();
但是报错。
The error is :"Caused by: java.sql.SQLSyntaxErrorException: ORA-00979: not a GROUP BY expression".
这个怎么写?请帮忙。提前致谢。
您需要select除聚合列外的所有其他列分组依据
select GRN_NO, IDENTIFICATION_NO, RBI_TRN_DATE, PERIOD_FROM, PERIOD_TO,
SUM(AMOUNT) AS AMOUNT
from PTAX_ECHALLAN_DATA
where IDENTIFICATION_NO in ('ECC0013056', '192009028150', '20150086699')
GROUP BY GRN_NO, IDENTIFICATION_NO, RBI_TRN_DATE, PERIOD_FROM, PERIOD_TO