SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
select c.last_name, c.first_name, t1.cnt from customer c join ( select r.customer_id, dense_rank() over(order by count(*) desc) as rank, count(*) as cnt from rental r group by r.customer_id ) t1 on c.customer_id = t1.customer_id where t1.rank <= 3 order by t1.cnt desc, c.last_name asc

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear