Hi! Could we please enable some services and cookies to improve your experience and our website?

SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share code      Blog   Popular   FAQ

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

Copy Format Clear
/* relative share of each film category in - total rental revenue - total number of rentals */ SELECT c.name AS category, SUM(p.amount) / SUM(SUM(p.amount)) OVER () AS relative_rental_amount, COUNT(*) / SUM(COUNT(*)) OVER () AS relative_rentals_count FROM rental AS r JOIN payment AS p ON p.rental_id = r.rental_id -- each payment belongs to one rental JOIN inventory AS i ON i.inventory_id = r.inventory_id JOIN film_category AS fc ON fc.film_id = i.film_id JOIN category AS c ON c.category_id = fc.category_id GROUP BY c.name ORDER BY relative_rental_amount DESC; ; show status like 'Last_query_cost';

Stuck with a problem? Got Error? Ask ChatGPT!