This code should work:
select max(rentalcount) into @maxrental from (select count(*) as rentalcount from rentals where year(rent_srt_date)=Yeartofind group by customerid) as rentaltable;
select customerid,customer_name,rental_id from
(select customerid,customer_name,rental_id,count(*) as rentalscount from customers inner join rentals on customers.customerid=rentals.customerid where year(rent_srt_date)=Yeartofind group by customers.customerid order by rentalcount desc) as rentalsgroup
where rentalscount=@maxrental;
You can also make an stored procedure and call it:
CREATE PROCEDURE `TopRental` (
vYear integer)
BEGIN
declare vMaximun integer default 0;
select max(rentalcount) into vMaximun from (select count(*) as rentalcount from rentals where year(rent_srt_date)=vYear group by customerid) as rentaltable;
select customerid,customer_name,rental_id from
(select customerid,customer_name,rental_id,count(*) as rentalscount from customers inner join rentals on customers.customerid=rentals.customerid where year(rent_srt_date)=vYear group by customers.customerid order by rentalcount desc) as rentalsgroup where rentalscount=vMaximun;
END
Then if you want ton know top rentals for year 2020, you write:
Call TopRental(2020);