我正在尝试同时使用order by和group by进行查询
但是我遇到了以下错误:
ORA-00979:不是GROUP BY表达式
这是查询的代码:
@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);
最佳答案
由于没有诸如COUNT之类的聚合函数,因此GROUP BY对数据库实际上没有任何意义。可怜的数据库想知道“组什么?”并发脾气。您当然可以在同一SQL语句中包含ORDER BY和GROUP BY。