简体   繁体   English

使用JPA和Hibernate与GROUP BY查询一起使用ORDER BY

[英]ORDER BY with GROUP BY query, using JPA and Hibernate

I'm trying to make a query using order by and group by at the same time But I'm taking a following error: 我试图同时使用order by和group by进行查询,但出现以下错误:

ORA-00979: not a GROUP BY expression ORA-00979:不是GROUP BY表达式

Here is query's code: 这是查询的代码:

  @Query("select distinct p from PointSpreadsheets p left join fetch p.shlSpreadsheetRegistersList srl" +
        "  WHERE (:BUAPP is null OR srl.buApprobation = :BUAPP)" +
        " AND (:STATUS is null OR p.idStatus = :STATUS)" +
        " AND (:CCAPP is null OR srl.ccApprobation = :CCAPP)" +
        " AND (:EMPLOYEE is null OR p.idEmployee = :EMPLOYEE)" +
        " AND (:CCLIST is null or srl.idCostCenter  = :CCLIST)" +
        " AND (p.idEmployee.idBusinessUnit IN (:BU))" +
        " AND (p.referencePeriod.idReferencePeriod IN :PERIODS)"
        + " GROUP BY"
        + " p.buApprobation, p.ccApprobation, p.dateBuApprobation,"
        + " p.dateCcApprobation, p.finalDate, p.idEmployee, p.idPeriodicity,"
        + " p.idSpreadsheet, p.idStatus, p.initialDate, p.referencePeriod"
        + " ORDER BY p.idEmployee")    
public List<PointSpreadsheets> PointSpreadsheetFilter(
        @Param("STATUS") BigDecimal status,
        @Param("BUAPP") BigDecimal buApprobation,
        @Param("CCAPP") BigDecimal ccApprobation,
        @Param("PERIODS") List<BigDecimal> periods,
        @Param("EMPLOYEE") Employees employee,
        @Param("BU") List<BusinessUnits> businessUnits,
        @Param("CCLIST") CostCenter cc);

Since there is no aggregate function, like COUNT or something else, the GROUP BY doesn't really mean anything to the database. 由于没有诸如COUNT之类的聚合函数,因此GROUP BY对数据库实际上没有任何意义。 The poor Database is wondering "group what ?" 可怜的数据库想知道“ 什么分组?” and throws a tantrum. 并发脾气。 You can certainly have ORDER BY and GROUP BY in the same SQL statement. 您当然可以在同一SQL语句中包含ORDER BYGROUP BY

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM