I have the following problem:
1) I have successfully managed to create a result displaying JUST the revenues of multiple movies (count how often it was rented * the rental rate). [Example A]
2) Now I want to get the average of this. I have managed to do it if I write another query around it [Example B], but I want to enclose it into the same query if possible. [Example C - which gives me an error]. Is this at all possible?
Example A:
SELECT COUNT(r.rental_id) * f.rental_rate AS Revenue
FROM film f, rental r, inventory i
WHERE i.inventory_id = r.inventory_id
AND f.film_id = i.film_id
GROUP BY f.title
ORDER BY Revenue DESC
Example B: (How I could make it work - encapsulated query)
SELECT AVG(B.Revenue)
FROM (
SELECT COUNT(r.rental_id) * f.rental_rate AS Revenue
FROM film f, rental r, inventory i
WHERE i.inventory_id = r.inventory_id
AND f.film_id = i.film_id
GROUP BY f.title
ORDER BY Revenue DESC ) B
Example C: (How i want it to work - one single query)
SELECT AVG (COUNT(r.rental_id) * f.rental_rate) AS Revenue
FROM film f, rental r, inventory i
WHERE i.inventory_id = r.inventory_id
AND f.film_id = i.film_id
GROUP BY f.title
ORDER BY Revenue DESC
Example C gives: "Error Code: 1111 \n Invalid use of group function"