select
f.title,
f.film_id,
r.rental_date,
r.return_date,
p.payment_date,
f.rental_rate,
(f.rental_rate - p.amount) as lateness_penalty,
p.amount
from payment as p
join rental as r on p.customer_id = r.customer_id
join inventory as i on r.inventory_id = i.inventory_id
join film as f on i.film_id = f.film_id
where p.customer_id = (select customer_id from customer where first_name = 'DOROTHY' and last_name = 'TAYLOR')
and year(rental_date) = 2005
and month(rental_date) = 8
and month(payment_date) = 8
UNION ALL
select
'Total' AS title,
NULL AS film_id,
NULL AS rental_date,
NULL AS return_date,
NULL AS payment_date,
sum(f.rental_rate),
sum(f.rental_rate - p.amount),
sum(p.amount)
from payment as p
join rental as r on p.customer_id = r.customer_id
join inventory as i on r.inventory_id = i.inventory_id
join film as f on i.film_id = f.film_id
where p.customer_id = (select customer_id from customer where first_name = 'DOROTHY' and last_name = 'TAYLOR')
and year(rental_date) = 2005
and month(rental_date) = 8
and month(payment_date) = 8
order by payment_date;
;
show status like 'Last_query_cost';