Data Nerds! This repo contains all the files needed to follow along my free course: Intermediate SQL for Data Analytics
![]()
🙋🏼♂️ Course Leader: Luke Barousse
🎬 Course Producer: Kelly Adams
📺 Video Editor: Brannon Linder
- About Course - (Open in Colab)
- Colab Notebooks - (Open in Colab)
- Database Overview - (Open in Colab)
- Basic Aggregation - (Open in Colab)
- Statistical Aggregations - (Open in Colab)
- Advanced Segmentation - (Open in Colab)
- Syntax - (Open in Colab)
- Aggregation - (Open in Colab)
- Ranking - (Open in Colab)
- Lag Lead - (Open in Colab)
- Frame Clause - (Open in Colab)
- View Intro - (Open in Colab)
- Project Cohort Revenue - (Open in Colab)
- Install VSCode - (Open in Colab)
- Conditional Handle Nulls - (Open in Colab)
- String Formatting - (Open in Colab)
- Project Customer Segmentation - (Open in Colab)
- Explain Intro - (Open in Colab)
- Optimization Techniques - (Open in Colab)
- Project Customer Retention - (Open in Colab)
Recommended to start the course.
- Google Account
- Click the "Open in Colab" button at top of any notebook.
No module named 'psycopg'error? Your copy of the notebook is out of date (copies saved to Google Drive don't update). In the setup cell, change%sql postgresql://to%sql postgresql+psycopg2://, then click Runtime > Restart session and run all. Or re-open the notebook with its "Open in Colab" button.
Second half of course uses this method.
- Download the Contoso database.
- Open pgAdmin 4.
- In Object Explorer, connect to your PostgreSQL server.
- Right-click on "Databases" > "Create" > "Database...".
- Enter
contoso_100kfor "Database" and click "Save". - In Object Explorer, right-click on the
contoso_100kdatabase > "PSQL Tool". - In the PSQL Tools Window, enter
\i [path to contoso_100k.sql]and press enter.
\i '/Users/lukebarousse/Desktop/contoso_100k.sql'
- If necessary, in the Query Tool, set default password for the
postgresuser topassword.
⚠ If you have sensitive information in your server DO NOT do this step; also not required if this is already your password⚠️
ALTER USER postgres WITH PASSWORD 'password';
How Kelly & I built the course; not recommended for beginners.
- PostgreSQL Installed
- Anaconda Installed
- Database Running Locally
- Create a new conda environment with
ipykernel,pandas, andmatplotlib:
conda create -n sql_course python=3.11 ipykernel pandas matplotlib
- Activate the environment:
conda activate sql_course
- Install the
jupysqlandpsycopg2packages:
conda install -c conda-forge jupysql psycopg2
- Upgrade
jupysql, necessary due to this issue:
pip install --upgrade jupysql
- Activate the
sql_courseenvironment in the notebook. - Connect to the database with the
psycopg2driver named in the URL (the setup cell of each notebook already does this). Without+psycopg2, SQLAlchemy 2.1+ looks for thepsycopgdriver and fails withNo module named 'psycopg'.
%sql postgresql+psycopg2://postgres:password@localhost:5432/contoso_100k
- If you find an error in this repo, please feel free to make a pull request by:
- Forking the repo
- Making any changes
- Submitting a pull request

