我有这样的代码,它得到了应用程序中每天的用户数量。
List<UserApplication> usersOfCurrentMonth = userApplicationRepository.getUsersOfCurrentMonth();
Map<Object, Long> dailyUserActivity = usersOfCurrentMonth.stream().collect(Collectors.groupingBy(a-> ((UserApplication)a).getCreationDate(), Collectors.counting()));查询
@Query(value = "select * from user_application a where year(a.creationDate) = year(current_date) and month(a.creationDate) = month(current_date)", nativeQuery = true)
List<UserApplication> getUsersOfCurrentMonth();效果很好
2020-03-30T14:21:09.003+0000: 1但是,我错过了这个月剩下的日子,。有没有办法把0加到这个月的所有其他日子?
例如:
2020-03-01T14:21:09.003+0000: 0
2020-03-02T14:21:09.003+0000: 0
....
2020-03-30T14:21:09.003+0000: 1发布于 2020-03-30 14:36:30
您可以确定当前月份的天数,然后对所有天数进行循环,使用computeIfAbsent将结果设置为零。
https://stackoverflow.com/questions/60932709
复制相似问题