![](/img/trans.png)
[英]Spring Data JPA - How can I fetch data from a Date column using only month and day?
[英]How can I return date and count of records for that date using spring data jpa?
我想按日期返回事件计数。下面是我的代码
@Query(value = "select DATE(e.startTime) as day,count(distinct e.id) as eventCount from events e " +
"where e.clientId=:clientId and e.startTime>=:firstDay and e.startTime<=:lastDay group by DATE(e.startTime)",nativeQuery = true)
Map<Integer, Integer> getClientEventsCountByDay(@Param(value = "clientId") Integer clientId,
@Param(value = "firstDay") String firstDay,
@Param(value = "lastDay") String lastDay);
输入是clientId=2510,firstDay=2019-01-01,lastDay=2019-01-31
此查询抛出以下错误
引起:org.springframework.dao.IncorrectResultSizeDataAccessException: result 返回多个元素; 嵌套异常是 javax.persistence.NonUniqueResultException: result 返回多个元素
试试改成这个
List<Map<Integer, Integer>> getClientEventsCountByDay(@Param(value = "clientId") Integer clientId,
@Param(value = "firstDay") String firstDay,
@Param(value = "lastDay") String lastDay);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.