按日期分组 - jpa2 - postgres

Group by date - jpa2 - postgres

我正在努力寻找一个合适的示例来按日期而不是 jpql 中的日期时间进行分组。请注意,我正在连接到 postgres 数据库。

查询如下所示:

@Query("select new example.model.ExampleModel(te.dateCreated, te.transactionStatus, sum(te.amount), count(te)) from ExampleEntity te group by te.dateCreated, te.transactionStatus")
fun findAggregatedExamples(): List<ExampleModel>

我需要将构造函数 arg 转换为日期并将分组依据转换为日期。

设法在 here

中找到有用的东西

工作代码:

@Query("select new example.model.ExampleModel(cast(te.dateCreated as date), te.transactionStatus, sum(te.amount), count(te)) from ExampleEntity te group by cast(te.dateCreated as date), te.transactionStatus")
fun findAggregatedExamples(): List<ExampleModel>

构造函数 arg0 必须从 LocalDateTime 更改为 java.util.Date。