我正在尝试使用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);
答案 0 :(得分:1)
由于没有聚合功能,例如 COUNT 或其他内容, GROUP BY 对数据库没有任何意义。可怜的数据库想知道“组什么?”并发脾气。您当然可以在同一个SQL语句中使用 ORDER BY 和 GROUP BY 。