The following SQL query counts the number of users in specific percentage ranges by using criteria on the join clause. How do you express the query in JPAQL? You may use the table names as entity names...Ill get the picture.
Code:
select e.location_id, count(p1.*) AS p1, count(p2.*) AS p2, count(p3.*) AS p3, count(p4.*) AS p4, count(p5.*) AS p5, count(p6.*) AS p6
from monthly_participation_rates p1
inner join enrollments e
on p1.enrollment_id = e.id
left outer join monthly_participation_rates p2
on p1.id = p2.id
and p2.rounded_total_rate >= 100
left outer join monthly_participation_rates p3
on p1.id = p3.id
and p3.rounded_total_rate <= 99
and p3.rounded_total_rate >= 75
left outer join monthly_participation_rates p4
on p1.id = p4.id
and p4.rounded_total_rate <= 74
and p4.rounded_total_rate >= 50
left outer join monthly_participation_rates p5
on p1.id = p5.id
and p5.rounded_total_rate <= 49
and p5.rounded_total_rate >= 1
left outer join monthly_participation_rates p6
on p1.id = p6.id
and p6.rounded_total_rate <= 0
where p1.month_id = -1
group by e.location_id;