【发布时间】:2019-02-21 07:25:33
【问题描述】:
我想按日期返回事件计数。下面是我的代码
@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:结果 返回多个元素;嵌套异常是 javax.persistence.NonUniqueResultException:结果返回超过 一个元素
【问题讨论】:
-
这可能会对您有所帮助。 stackoverflow.com/questions/12270991/….
-
我的目标是返回日期,计为关键值,如相关图片所示。如果我正在获取地图列表,那么每天我都有一张不必要的地图。你能建议实现这一目标的其他方法?最终目标是返回日期并计为键值。
标签: java hibernate spring-data-jpa