I’m trying to only select the MAX value for a summed column
select rental.member_id,
rental.rental_id,
sum(rental_line.Qty) as TotalRentals
from Rental
INNER JOIN rental_line
on rental.rental_id =rental_line.rental_id
where MONTHS_BETWEEN(sysdate, datein)<(12)
group by rental.member_id,
rental.rental_id,
SUM(TotalRentals) = MAX(SUM(TotalRentals));
Any ideas?
You could sort result set of the query by
TotalRentals(3) in descending order and then pick up the first row usingrownumpseudocolumn: