Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void findEmployeesMaximumSalaries() {
- List<Employee> employeesGroupBy = em.createQuery("SELECT e FROM Employee e GROUP BY e.department.id " +
- "HAVING MAX(e.salary) NOT BETWEEN 30000 and 70000", Employee.class)
- .getResultList();
- List<Employee> employees = em.createQuery("SELECT e FROM Employee e ", Employee.class)
- .getResultList();
- for (Employee d : employeesGroupBy) {
- System.out.printf("%s %s%n"
- , d.getDepartment().getName()
- , getMaxSalary(d.getDepartment().getName(), employees));
- }
- }
- private BigDecimal getMaxSalary(String name, List<Employee> employees) {
- BigDecimal result;
- Employee employee = employees.stream().filter(f -> f.getDepartment().getName().equals(name))
- .sorted((f, s) -> s.getSalary().compareTo(f.getSalary()))
- .limit(1)
- .findFirst()
- .orElse(null);
- result = employee.getSalary();
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement