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      Blog   Popular

SQLize.online is a free online SQL environment for quickly running, experimenting with and sharing code. You can run your SQL code on top of the most popular RDBMS including MySQL, MariaDB, SQLite, PostgreSQL, Oracle and Microsoft SQL Server.

Copy Format Clear
/* Relative share of each film category in – the total number of rentals (relative_rentals_count) – the total rental revenue (USD) (relative_rental_amount) */ SELECT c.name AS category, SUM(p.amount) / ( SELECT SUM(amount) FROM payment ) AS relative_rental_amount, COUNT(*) / ( SELECT COUNT(*) FROM payment ) AS relative_rentals_count FROM payment AS p -- start with the biggest table once JOIN rental AS r ON r.rental_id = p.rental_id 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.category_id ORDER BY relative_rental_amount DESC; ; show status like 'Last_query_cost';

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear