SQL Explorer
Demo Environment
This environment resets nightly. Any data or connections you add are public.
SQL Explorer
New Query
Playground
Connections
Annotations
Logs
Favorites
Movie recommendations
no such table: rental
Title
northwind.db
sqlite-sakila.db
MSSQL
trial
Connection
please recommend 3 movies i might want to watch. Look at the most popular few movies from each category (based on # of rentals) and then recommend a random set, so that i get some different suggestions each time i refresh.
Description
SQL
WITH rental_counts AS ( SELECT f.film_id, f.title, fc.category_id, COUNT(r.rental_id) AS rental_count FROM rental r JOIN inventory i ON r.inventory_id = i.inventory_id JOIN film f ON i.film_id = f.film_id JOIN film_category fc ON f.film_id = fc.film_id GROUP BY f.film_id, fc.category_id ), popular_films AS ( SELECT film_id, title, category_id, rental_count, ROW_NUMBER() OVER (PARTITION BY category_id ORDER BY rental_count DESC) AS rn FROM rental_counts ) SELECT film_id, title FROM popular_films WHERE rn <= 3 -- Limit to the most popular few films per category ORDER BY RANDOM() -- Randomly select 3 films LIMIT 3;
Assistant Example
Save & Run
Save Only
Download...
CSV
JSON
Show Schema
Hide Schema
SQL Assistant
Loading...
Assistant prompt
"Ask Assistant" to try and automatically fix the issue. The assistant is already aware of error messages & context.
Ask Assistant
Avg. execution: 31.254ms. Query created by admin on 2024-05-17.
History