diff --git a/lab-sql-9.ipynb b/lab-sql-9.ipynb
new file mode 100644
index 0000000..9ff620b
--- /dev/null
+++ b/lab-sql-9.ipynb
@@ -0,0 +1,388 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "id": "de221430",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "'\\n!pip install mysql.connector\\n!pip install mysql.connector.python\\n!pip install sqlalchemy\\n!pip install pymysql\\n\\n'"
+ ]
+ },
+ "execution_count": 1,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "'''\n",
+ "!pip install mysql.connector\n",
+ "!pip install mysql.connector.python\n",
+ "!pip install sqlalchemy\n",
+ "!pip install pymysql\n",
+ "\n",
+ "'''"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "id": "37d20b1b",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import pymysql\n",
+ "from sqlalchemy import create_engine\n",
+ "import pandas as pd\n",
+ "import numpy as np"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "id": "b4268fa3",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "········\n"
+ ]
+ }
+ ],
+ "source": [
+ "import getpass\n",
+ "password = getpass.getpass()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 17,
+ "id": "1639585c",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " customer_name | \n",
+ " nr_rentals_may | \n",
+ " nr_rentals_june | \n",
+ "
\n",
+ " \n",
+ " | customer_id | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 197 | \n",
+ " SUE PETERS | \n",
+ " 8 | \n",
+ " 8 | \n",
+ "
\n",
+ " \n",
+ " | 176 | \n",
+ " JUNE CARROLL | \n",
+ " 5 | \n",
+ " 8 | \n",
+ "
\n",
+ " \n",
+ " | 371 | \n",
+ " BILLY POULIN | \n",
+ " 6 | \n",
+ " 7 | \n",
+ "
\n",
+ " \n",
+ " | 109 | \n",
+ " EDNA WEST | \n",
+ " 7 | \n",
+ " 5 | \n",
+ "
\n",
+ " \n",
+ " | 196 | \n",
+ " ALMA AUSTIN | \n",
+ " 4 | \n",
+ " 8 | \n",
+ "
\n",
+ " \n",
+ " | ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ "
\n",
+ " \n",
+ " | 440 | \n",
+ " BERNARD COLBY | \n",
+ " 1 | \n",
+ " 0 | \n",
+ "
\n",
+ " \n",
+ " | 487 | \n",
+ " HECTOR POINDEXTER | \n",
+ " 0 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " | 555 | \n",
+ " DWIGHT LOMBARDI | \n",
+ " 0 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " | 598 | \n",
+ " WADE DELVALLE | \n",
+ " 0 | \n",
+ " 1 | \n",
+ "
\n",
+ " \n",
+ " | 195 | \n",
+ " VANESSA SIMS | \n",
+ " 0 | \n",
+ " 0 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
599 rows × 3 columns
\n",
+ "
"
+ ],
+ "text/plain": [
+ " customer_name nr_rentals_may nr_rentals_june\n",
+ "customer_id \n",
+ "197 SUE PETERS 8 8\n",
+ "176 JUNE CARROLL 5 8\n",
+ "371 BILLY POULIN 6 7\n",
+ "109 EDNA WEST 7 5\n",
+ "196 ALMA AUSTIN 4 8\n",
+ "... ... ... ...\n",
+ "440 BERNARD COLBY 1 0\n",
+ "487 HECTOR POINDEXTER 0 1\n",
+ "555 DWIGHT LOMBARDI 0 1\n",
+ "598 WADE DELVALLE 0 1\n",
+ "195 VANESSA SIMS 0 0\n",
+ "\n",
+ "[599 rows x 3 columns]"
+ ]
+ },
+ "execution_count": 17,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "connection_string = 'mysql+pymysql://root:' + password + '@localhost/bank'\n",
+ "engine = create_engine(connection_string)\n",
+ "data = pd.read_sql_query('select * from sakila.rentals_may_june', engine)\n",
+ "data = data.set_index('customer_id')\n",
+ "data"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 20,
+ "id": "6eae4c81",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "def compare_rentals_may_june(df):\n",
+ " df['most_rentals'] = np.where(df['nr_rentals_may'] > df['nr_rentals_june'], 'may',\n",
+ " np.where(df['nr_rentals_may'] < df['nr_rentals_june'], 'june', 'equal'))\n",
+ " return df"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 21,
+ "id": "0e35377b",
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " customer_name | \n",
+ " nr_rentals_may | \n",
+ " nr_rentals_june | \n",
+ " most_rentals | \n",
+ "
\n",
+ " \n",
+ " | customer_id | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 197 | \n",
+ " SUE PETERS | \n",
+ " 8 | \n",
+ " 8 | \n",
+ " equal | \n",
+ "
\n",
+ " \n",
+ " | 176 | \n",
+ " JUNE CARROLL | \n",
+ " 5 | \n",
+ " 8 | \n",
+ " june | \n",
+ "
\n",
+ " \n",
+ " | 371 | \n",
+ " BILLY POULIN | \n",
+ " 6 | \n",
+ " 7 | \n",
+ " june | \n",
+ "
\n",
+ " \n",
+ " | 109 | \n",
+ " EDNA WEST | \n",
+ " 7 | \n",
+ " 5 | \n",
+ " may | \n",
+ "
\n",
+ " \n",
+ " | 196 | \n",
+ " ALMA AUSTIN | \n",
+ " 4 | \n",
+ " 8 | \n",
+ " june | \n",
+ "
\n",
+ " \n",
+ " | ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ "
\n",
+ " \n",
+ " | 440 | \n",
+ " BERNARD COLBY | \n",
+ " 1 | \n",
+ " 0 | \n",
+ " may | \n",
+ "
\n",
+ " \n",
+ " | 487 | \n",
+ " HECTOR POINDEXTER | \n",
+ " 0 | \n",
+ " 1 | \n",
+ " june | \n",
+ "
\n",
+ " \n",
+ " | 555 | \n",
+ " DWIGHT LOMBARDI | \n",
+ " 0 | \n",
+ " 1 | \n",
+ " june | \n",
+ "
\n",
+ " \n",
+ " | 598 | \n",
+ " WADE DELVALLE | \n",
+ " 0 | \n",
+ " 1 | \n",
+ " june | \n",
+ "
\n",
+ " \n",
+ " | 195 | \n",
+ " VANESSA SIMS | \n",
+ " 0 | \n",
+ " 0 | \n",
+ " equal | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
599 rows × 4 columns
\n",
+ "
"
+ ],
+ "text/plain": [
+ " customer_name nr_rentals_may nr_rentals_june most_rentals\n",
+ "customer_id \n",
+ "197 SUE PETERS 8 8 equal\n",
+ "176 JUNE CARROLL 5 8 june\n",
+ "371 BILLY POULIN 6 7 june\n",
+ "109 EDNA WEST 7 5 may\n",
+ "196 ALMA AUSTIN 4 8 june\n",
+ "... ... ... ... ...\n",
+ "440 BERNARD COLBY 1 0 may\n",
+ "487 HECTOR POINDEXTER 0 1 june\n",
+ "555 DWIGHT LOMBARDI 0 1 june\n",
+ "598 WADE DELVALLE 0 1 june\n",
+ "195 VANESSA SIMS 0 0 equal\n",
+ "\n",
+ "[599 rows x 4 columns]"
+ ]
+ },
+ "execution_count": 21,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "compare_rentals_may_june(data)"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3 (ipykernel)",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.11.5"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 5
+}
diff --git a/lab-sql-9.sql b/lab-sql-9.sql
new file mode 100644
index 0000000..b7e5afb
--- /dev/null
+++ b/lab-sql-9.sql
@@ -0,0 +1,20 @@
+create temporary table sakila.rentals_may as select * from sakila.rental where month(rental_date)=5;
+create temporary table sakila.rentals_june as select * from sakila.rental where month(rental_date)=6;
+
+select concat(cust.first_name, " ", cust.last_name) as customer_name, count(may.rental_id) as nr_rentals_may
+from sakila.customer cust left join sakila.rentals_may may
+on may.customer_id = cust.customer_id
+group by cust.customer_id order by 2 desc;
+
+create table sakila.rentals_may_june
+as select cust.customer_id, concat(cust.first_name, " ", cust.last_name) as customer_name,
+count(distinct may.rental_id) as nr_rentals_may, count(distinct june.rental_id) as nr_rentals_june
+from
+sakila.customer as cust
+left join sakila.rentals_may as may
+on may.customer_id = cust.customer_id
+left join sakila.rentals_june as june
+on june.customer_id = cust.customer_id
+group by cust.customer_id order by (nr_rentals_may + nr_rentals_june) desc;
+
+select * from sakila.rentals_may_june;
\ No newline at end of file