with horror_films as (
select f.film_id, title
from film f
join film_category fc on f.film_id=fc.film_id
join category c on fc.category_id=c.category_id
where name = 'Horror' and rating = 'PG-13'),
rental_rank as (select title, FIRST_VALUE(first_name) over (partition by hf.film_id order by rental_date) as first_name,
FIRST_VALUE(last_name) over (partition by hf.film_id order by rental_date) as last_name
from horror_films hf
join inventory i on hf.film_id=i.film_id
join rental r on i.inventory_id=r.inventory_id
join customer c on r.customer_id=c.customer_id)
select distinct title, CONCAT(first_name, ' ', last_name) as first_customer
from rental_rank
order by title
;
show status like 'Last_query_cost';