I tried to solve this query by
select * from (select u.user_id,u.email_id,u.password,u.first_name,u.last_name,u.city,u.gender,
u.phone_no from user_details u inner join ride_users r on u.user_id=r.user_id
group by u.user_id,u.email_id,u.password,u.first_name,u.last_name,u.city,u.gender,u.phone_no
order by count(r.ride_id) desc) where rownum<4;
but it didn't match the test case.
Can anybody help me?
The other answer is really well spelled out, and much more elegant. This solution uses the rank function, spelled out as much as I could think of, and is a bit clunker. Just posting it to show there are always multiple ways to go about solving a problem. There is a right answer if you include "query optimization." But that is a bit down the road from answering a question like this.