SQL views for querying and analysing data from a relational movie shipment database. Built as a database project using PostgreSQL.
README.md: This file, providing an overview of the project and setup instructions.MovieDirect_Data.sql: The SQL script required to create the database schema (tables) and populate them with the necessary data.movie_database_views.sql: The main SQL script containing theCREATE VIEWstatements.
To run this project and test the views, follow these steps:
- Create a Database: In your chosen SQL environment (e.g., PostgreSQL, MySQL, SQL Server), create a new, empty database.
- Load Data: Execute the
MovieDirect_Data.sqlscript. This will create the required tables (Movies,Customers,Stock,Shipments) and insert the sample data. - Create Views: Execute
movie_database_views.sql. This will create all the views. - Query the Views: You can now query the data using the views. For example:
SELECT * FROM movie_summary;
SELECT * FROM binge_watcher;Provides a simple summary of each movie available in stock, combining information from the Movies and Stock tables.
Lists all historical shipments that occurred before 1 January 2010, including the name of the customer who received the shipment.
Finds all movies in the database directed by Ron Howard.
Calculates a potential new retail price for all items in stock. The new_price column represents a 25% increase on the current retail_price.
Calculates the total profit generated from movies that have been shipped. Profit is calculated as the sum of retail prices minus the sum of cost prices for all shipped units of a particular movie. Only includes movies with at least one shipment record.
Identifies customers who can be considered "binge watchers" by finding those who have had more than one movie shipped to them on the same day.
Lists all customers who have never had the movie 'Star Wars: Episode V - The Empire Strikes Back' shipped to them. Uses a NOT EXISTS subquery to filter the customer list.
Identifies the customer who had '12 Angry Men' shipped, but only if they were the single, sole customer to have ever received that movie. If more than one customer has received the movie, this view returns no results.
- Output Ordering: No ordering requirements were specified for this schema, so
ORDER BYclauses have been omitted. - Rounding: Financial values in
retail_price_hikeandprofits_from_movieare returned as precise floating-point numbers. In a production environment, these would likely be rounded to two decimal places. - Distinct Values: The current implementation preserves duplicates where the underlying data allows. For views like
richieorbinge_watcher, this means a movie title or customer name could potentially appear multiple times. - Grouping Logic: In views requiring aggregation (e.g.,
profits_from_movie), grouping has been performed by the primary key (movie_id) in addition to other attributes likemovie_titleto ensure correct and unambiguous aggregation.