I am trying to get a solution to the following sql problem on codewars: Write an SQL query to retrieve the top 5 customers who have rented the most movies, excluding customers who have rented at least one movie with an 'NC-17' rating. Subqueries are forbidden to make the task a bit curiouser - you can use select only once
This is what I have tried:
select customer.customer_id,
first_name||' '||last_name as full_name,
count(*) as total_rentals
from customer
inner join rental on customer.customer_id = rental.customer_id
inner join inventory on rental.inventory_id = inventory.inventory_id
right join film on inventory.film_id = film.film_id
where film.rating !='NC-17'
group by customer.customer_id,first_name||' '||last_name
order by count(*)desc,last_name
limit 5
The problem is that the above excludes only the rows where the film rating is NC-17. I need to exclude whoever has watched a movie with a NC-17 rating.I am limited as the challenge only allows me to use select once so i cant use subqueries