【问题标题】:Group by date - jpa2 - postgres按日期分组 - jpa2 - postgres
【发布时间】:2019-02-09 04:55:34
【问题描述】:

我正在努力寻找一个合适的示例来按日期而不是 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>

我需要将 contructor arg 转换为 date 并将 group by 转换为 date。

【问题讨论】:

标签: java postgresql spring-data jpa-2.0


【解决方案1】:

设法在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。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-19
    • 1970-01-01
    • 1970-01-01
    • 2011-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多