An open API service indexing awesome lists of open source software.

https://github.com/harmain-ali/postgre-sql-for-data-science


https://github.com/harmain-ali/postgre-sql-for-data-science

dataanalytics database database-design database-management datascience dataset postgres postgresql postgresql-database postgressql sql sqlite

Last synced: 2 months ago
JSON representation

Awesome Lists containing this project

README

          

## πŸ“š PostgreSQL Cheatsheet β€” From Zero to Hero πŸš€

![PostgreSQL](https://img.shields.io/badge/PostgreSQL-336791?style=for-the-badge\&logo=postgresql\&logoColor=white)
![SQL](https://img.shields.io/badge/SQL-Basics-blue?style=for-the-badge)
![Joins](https://img.shields.io/badge/SQL-JOINS-green?style=for-the-badge)
![Queries](https://img.shields.io/badge/150%2B-Queries-orange?style=for-the-badge)
![Data Science](https://img.shields.io/badge/Data%20Science-Friendly-purple?style=for-the-badge)

## πŸ”₯ What’s Inside?

This repo is your **ultimate PostgreSQL cheatsheet**, carefully crafted to take you from **absolute beginner β†’ advanced SQL master**.

* βœ… Complete **PostgreSQL Cheatsheet** with theory + SQL queries + pgAdmin steps
* βœ… Covers **0 β†’ Hero topics** (Databases, Tables, Queries, Joins, Subqueries, Functions, Views, Indexes, Transactions, Security, and more)
* βœ… A **sample database (dvdrental)** with **150+ solved real-world questions** for practice
* βœ… Perfect for **Data Scientists, Analysts, and Developers**

## πŸ—‚οΈ Topics Covered

* Database Creation & Connections
* Tables (Create, Modify, Drop)
* Data Insertion, Import & Export
* Filtering (WHERE, IN, BETWEEN, LIKE)
* Sorting & Limiting
* Aggregations & GROUP BY
* Joins (INNER, LEFT, RIGHT, FULL, CROSS)
* Subqueries & CTEs (WITH)
* Views & Materialized Views
* Functions, Procedures & Triggers
* Window Functions
* Indexes & Performance Optimization
* Transactions & Concurrency Control
* Security & User Management
* Connecting PostgreSQL with Python (psycopg2 & SQLAlchemy)

## πŸ“ Sample Practice Questions

βœ” **Basic SELECT Queries** β†’ List all customers, find films longer than 100 mins, display rentals on a given date

βœ” **Filtering** β†’ Customers from London, films with rental rate between 2–5, NULL checks

βœ” **Sorting & Limiting** β†’ Top 10 expensive films, earliest rentals, most recent payments

βœ” **Joins** β†’ Films with categories, customers with city names, rentals with staff names

βœ” **Aggregations** β†’ Count films, calculate average payments, revenue per store

βœ” **Subqueries** β†’ Most rented film, top customers, films longer than average

βœ” **Complex Joins** β†’ Top 5 customers by rentals, total revenue per country, least rented film

πŸ“Œ More than **150+ solved examples** included using **dvdrental** database.

## πŸš€ How to Use

1. Clone the repo

```bash
git clone https://github.com/your-username/postgresql-cheatsheet.git
cd postgresql-cheatsheet
```
2. Import the sample **dvdrental** database into PostgreSQL.
3. Explore `postgre_sql_cheatsheat.ipynb` for theory + queries.
4. Try solving practice questions (`DVD-RENTAL-PRACTICE-QUESTIONS.txt`) in your own database.

## πŸ”— Related Resources

Expand your learning beyond PostgreSQL:

* πŸ“Š [EDA Guide (Exploratory Data Analysis)](https://github.com/Harmain-Ali/Complete-EDA-Guide)
* 🐍 [SQLAlchemy Cheatsheet](https://github.com/Harmain-Ali/SQLAlchemy-For-DataScience)

## 🌟 Support

If you find this helpful:

* ⭐ **Star this repo** to support my work
* πŸ‘€ **Follow me** for more data science & SQL content
* πŸ”” Stay tuned for upcoming **Pandas Cheatsheet** & more advanced guides

## 🏷️ Tags

`postgresql` `sql` `cheatsheet` `database` `data-science` `joins` `queries` `data-analysis` `sqlalchemy` `pgadmin` `practice-questions` `dvdrental`

⚑ With this guide, you’ll go from **writing your first SELECT query** β†’ **mastering window functions, joins, optimization, and real-world analysis**.