Coder Social home page Coder Social logo

lab-sql-9's Introduction

logo_ironhack_blue 7

Lab | SQL Queries 9

In this lab, you will be using the Sakila database of movie rentals. You have been using this database for a couple labs already, but if you need to get the data again, refer to the official installation link.

The database is structured as follows: DB schema

Instructions

In this lab we will find the customers who were active in consecutive months of May and June. Follow the steps to complete the analysis.

  • Create a table rentals_may to store the data from rental table with information for the month of May.

  • Insert values in the table rentals_may using the table rental, filtering values only for the month of May.

  • Create a table rentals_june to store the data from rental table with information for the month of June.

  • Insert values in the table rentals_june using the table rental, filtering values only for the month of June.

  • Check the number of rentals for each customer for May.

  • Check the number of rentals for each customer for June.

  • Create a Python connection with SQL database and retrieve the results of the last two queries (also mentioned below) as dataframes:

    • Check the number of rentals for each customer for May

    • Check the number of rentals for each customer for June

      Hint: You can store the results from the two queries in two separate dataframes.

  • Write a function that checks if customer borrowed more or less films in the month of June as compared to May.

    Hint: For this part, you can create a join between the two dataframes created before, using the merge function available for pandas dataframes. Here is a link to the documentation for the merge function.

lab-sql-9's People

Contributors

haggarw3 avatar ironhack-edu avatar sandrabosk avatar

Watchers

 avatar  avatar

lab-sql-9's Issues

Task Unclear

@sandrabosk

Last task is unclear, students couldn't figure out. Also, they are trying to get everything in one query with lots of joins (check if that is ok). Also, 'most rented film category by client' solution suggestion is not returning the desired result. Solved it with subqueries:

SELECT customer, category_name FROM
(SELECT rental.customer_id as customer, count(rental.rental_id) as total_rentals, film_category.category_id, category.name as category_name,
row_number() over (partition by rental.customer_id order by count(rental.rental_id) desc) as ranking_max_rented_category
FROM rental
INNER JOIN inventory ON rental.inventory_id = inventory.inventory_id
INNER JOIN film_category ON inventory.film_id = film_category.film_id
INNER JOIN category ON film_category.category_id = category.category_id
GROUP BY rental.customer_id, film_category.category_id, category.name) AS table_popular_category
WHERE ranking_max_rented_category = 1
ORDER BY customer;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.