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
Title
sqlite-sakila.db
MSSQL
db_1.db
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
Preview
Pivot
  Execution time: 33.28 ms
Showing
of 3 total rows.
film_id
title
Sum
2352.0
Avg
784.0
Min
738.0
Max
869.0
NUL
0.0
0
869
SUSPECTS QUILLS
1
738
ROCKETEER MOTHER
2
745
ROSES TREASURE
Link to this
Download CSV
Avg. execution: 32.528ms. Query created by admin on 2024-05-17.
History