10 GitHub Repositories to Master SQL for Data Science

Ten free GitHub repositories, arranged as a learning path, that take you from SQL interview practice and realistic sample data to window functions, query performance tuning, and production analytics with dbt.



10 GitHub Repositories to Master SQL for Data Science

Most people learn SQL in the same order. First SELECT and WHERE, then JOIN and GROUP BY. After that, progress tends to stall, because the next step is not another keyword. It is knowing how to rank rows without a messy self-join, why a query that ran in two seconds last month now takes two minutes, and how to turn a folder of one-off queries into something your team can trust.

A lot of the best material for that next step is free on GitHub, and it is kept current by people who use SQL every day. The doocs/leetcode repository has worked solutions to 309 SQL interview problems. The free Data Engineering Zoomcamp has passed 46,000 stars teaching SQL on BigQuery, DuckDB and dbt.

This article covers 10 GitHub repositories to master SQL for data science, arranged as a learning path. You start with SQL interview questions and realistic practice data, move into advanced SQL patterns like window functions, learn SQL performance tuning, and finish with the tools analytics teams use in production.

Here is the full list of the repositories covered in this article:

# Repository Stars Last commit What it teaches
1 doocs/leetcode 36.8k Nov 2026 SQL interview problems with solutions
2 DataExpert-io/data-engineer-handbook 45.0k Aug 2026 Roadmap, bootcamps and interview advice
3 datacharmer/test_db 4.5k Apr 2026 Realistic data to practice on
4 duckdb/duckdb 42.8k Nov 2026 Advanced analytical SQL on a laptop
5 dalibo/pev2 3.6k Nov 2026 Reading query plans
6 ankane/pghero 8.9k Oct 2026 Finding slow queries
7 sqlfluff/sqlfluff 10.0k Nov 2026 Clean, consistent SQL
8 tobymao/sqlglot 9.8k Nov 2026 Moving between SQL dialects
9 dbt-labs/dbt 14.1k Nov 2026 Production analytics with SQL
10 DataTalksClub/data-engineering-zoomcamp 46.6k Sep 2026 A full end-to-end project

1. doocs/leetcode

leetcode

doocs/leetcode is a huge collection of LeetCode solutions run by the doocs open source community and maintained mainly by Libin Yang, who still commits to it almost daily. Most people know it for algorithm problems, but its database section is the part data people should bookmark. It lists 309 SQL problems, each tagged Easy, Medium or Hard, with a written explanation and often more than one approach.

That explanation is what makes it better than grinding problems on your own. When you get stuck, you see why a solution works, not just the final query. The problems also repeat the same handful of ideas that interviewers love: ranking, running totals, consecutive streaks, medians and finding rows with no match.

2. DataExpert-io/data-engineer-handbook

data-engineer-handbook

If doocs gives you the problems, the Data Engineering Handbook gives you the map. It was started by Zach Wilson, a data engineer who runs the education platform DataExpert.io, and he still makes most of the commits. With about 45,000 stars, it is the second most starred repo on this list.

The repo is mostly curated links, but it is organized around what you actually need to do next. It points to a free 4-week beginner bootcamp and a free 6-week intermediate bootcamp, an interviews page, a list of hands-on projects, and more than 25 recommended books. For SQL specifically, the bootcamp material goes deep on data modeling: fact tables, dimension tables and how to design tables that analysts can query without pain.

Use this repo to plan rather than to practice. Read the interviews page before you start the doocs problems, so you know which topics show up most, and come back to the projects list once you finish this article.

3. datacharmer/test_db

datacharmer

Practicing on a five-row table hides most of the problems you will meet at work. test_db fixes that. It is the classic Employees sample database, with the schema designed by Giuseppe Maxia and data originally generated by Fusheng Wang and Carlo Zaniolo at Siemens Corporate Research. According to the README, it holds about 300,000 employee records and 2.8 million salary entries, and MySQL's own documentation uses it.

It is old data, but the repo is not abandoned. It is tested every week against current MySQL, MariaDB and Percona releases, and the README now covers PostgreSQL 16 and 17 as well. Millions of salary rows are enough to make a careless query noticeably slow, which is the kind of feedback you want while learning.

4. duckdb/duckdb

duckdb

For a long time, practicing serious analytical SQL meant installing a database server, creating users and loading data before you could write a single query. DuckDB removed all of that. Its citation file lists Mark Raasveldt and Hannes Mühleisen as its authors, the code is owned by the non-profit DuckDB Foundation, and commercial support comes from DuckDB Labs. The project is moving fast: the latest release on GitHub is v2.0.0, and the main branch gets commits every day.

The README explains why data scientists took to it so quickly. DuckDB runs "in-process", meaning it lives inside your Python script or notebook the way a library does. There is no server to manage. It reads CSV, Parquet, JSON and Excel files directly, and it supports the advanced features you need for analytics, such as window functions, nested subqueries and complex types like arrays and structs.

5. dalibo/pev2

dalibo

PEV2 (Postgres Explain Visualizer 2) turns PostgreSQL's wall of EXPLAIN plan text into a clickable tree. It is built and maintained by Dalibo, a PostgreSQL company, and its README credits the original pev project by Alex Tatiyants, which was first written in 2016 and is no longer updated. PEV2 picked up where it left off and still gets regular commits. You can use it without installing anything at explain.dalibo.com, or download a single HTML file and run it fully offline, which matters if your plans contain table names you can't share.

6. ankane/pghero

pghero

PEV2 helps once you know which query is slow. PgHero helps you find it in the first place. It is a performance dashboard for Postgres created by Andrew Kane, and its README notes that it is battle-tested at Instacart. Version 4.0 is the current major release, and it runs as a Docker image or inside a Rails app.

PgHero shows your slowest queries, unused and duplicate indexes, tables that need maintenance and connection usage, all on one page. Much of that information comes from a Postgres extension called pg_stat_statements, which you can also query yourself:

-- Enable once per database
-- (pg_stat_statements must also be listed in shared_preload_libraries)
CREATE EXTENSION IF NOT EXISTS pg_stat_statements;

-- The five queries that used the most total time
SELECT
    LEFT(query, 60)                     AS query_start,
    calls,                                                -- how many times it ran
    ROUND(total_exec_time::numeric, 0)  AS total_ms,      -- time across all runs
    ROUND(mean_exec_time::numeric, 2)   AS avg_ms         -- time per run
FROM pg_stat_statements
ORDER BY total_exec_time DESC
LIMIT 5;

The key idea here is sorting by total time, not average time. A report that takes 30 seconds but runs once a day costs far less than a 50-millisecond query that runs 200,000 times a day, which adds up to about 2.8 hours of database time. Beginners tend to tune the slow-looking query. Experienced people tune the one at the top of this list. The column names total_exec_time and mean_exec_time apply to PostgreSQL 13 and later.

7. sqlfluff/sqlfluff

sqlfluff

SQLFluff is a linter for SQL, a tool that reads your code and flags style problems and likely mistakes. Alan Cruickshank started it, and the changelog records its first alpha release on November 7, 2018. Today it has a wide contributor base, supports the 28 dialects listed in its README, including BigQuery, Snowflake, DuckDB and Postgres, and understands the Jinja templating that dbt uses.

Here is a quick query of the kind most of us write when we are in a hurry, saved as messy.sql:

select customer_id,SUM(amount) as Total
FROM orders o join customers c on o.customer_id=c.id
group by customer_id

Run two commands against it:

pip install sqlfluff

# Report every problem, with line, position and rule code
sqlfluff lint messy.sql --dialect postgres

# Rewrite the file to fix everything that can be fixed safely
sqlfluff fix messy.sql --dialect postgres

When we ran this with SQLFluff 4.5.0, lint reported 12 issues: mixed capitalization, missing spaces around =, an implicit join that should say inner join, table aliases without as, and column names that don't say which table they come from. After fix, the file looked like this:

select
    customer_id,
    SUM(amount) as total
from orders as o inner join customers as c on o.customer_id = c.id
group by customer_id

Three warnings were left, and that part is the real lesson. customer_id and amount are still unqualified, so a reader cannot tell whether they come from orders or customers. SQLFluff won't guess, because only you know which table you meant. The tool handles formatting so that code review can focus on logic. To share rules across a team, put them in a .sqlfluff file at the root of your project.

8. tobymao/sqlglot

sqlglot

SQL is a standard, but every database speaks its own dialect, and a data scientist can easily touch Postgres, BigQuery and DuckDB in the same month. SQLGlot, created by Toby Mao, is a SQL parser, transpiler and optimizer written in pure Python. Its README says it translates between more than 30 dialects, and it has no dependencies. It is also a great way to understand how SQL is structured, because it turns any query into a tree you can inspect and edit in code.

9. dbt-labs/dbt

dbt-labs

The tools so far help you write better individual queries. dbt changes how a whole team works with SQL. In the words of its README, it lets analysts and engineers "transform their data using the same practices that software engineers use to build applications." Each model is a SQL SELECT statement saved as a file. dbt works out the order to run them in, builds them as tables or views in your warehouse and runs tests on the results.

The repository, previously known as dbt-core, now lives at dbt-labs/dbt, and its main branch holds dbt v2.0, a ground-up rewrite in Rust released under the Apache 2.0 license. The README says it parses and compiles projects in a fraction of the time v1 needed. The Python-based v1 continues on the 1.latest branch, so older tutorials still apply, but new projects should start on v2.

The best way in is jaffle-shop, dbt Labs' official sandbox project built around a fictional restaurant. Its main branch now requires dbt v2.0.0, and if you'd rather skip setting up a cloud warehouse, there is a DuckDB version.

10. DataTalksClub/data-engineering-zoomcamp

data-engineering-zoomcamp

Reading about SQL only gets you so far. At some point you need a project that loads real data, models it and answers real questions, and that is what the Data Engineering Zoomcamp gives you. It is run by DataTalks.Club and led by Alexey Grigorev, who tops its instructor list and is still its most active committer. It is the most starred repository on this list.

The README describes it as a free 9-week course, and "familiarity with SQL" is one of its few prerequisites. You can follow it self-paced at any time, or join the next live cohort, which starts in January 2027 and adds graded homework, peer review and a certificate. For SQL learners, two modules matter most. Module 3 covers data warehousing in BigQuery, including a unit on partitioning vs. clustering. Module 4 covers analytics engineering with dbt on DuckDB and BigQuery, which brings items 4 and 9 from this list together in one project.

The course ends with a peer-reviewed final project. That project is the most useful thing to come out of this whole list, because it gives you SQL work you can actually show in an interview.

Wrapping Up

Don't try to work through all ten at once. Pick based on what you need right now. If you have an interview in the next few weeks, spend your time in doocs/leetcode and the Data Engineering Handbook's interviews page, and practice the patterns on test_db or in DuckDB so you see them on more than toy data. If you already work with data and your queries feel slow, start with PgHero to find the worst offender and PEV2 to understand it. If you want to move toward analytics engineering, go through jaffle-shop in dbt, keep SQLFluff running as you write, and use the Zoomcamp's final project as the piece you show employers.

Whichever route you take, the habit that matters most is the same: finish one repository before you open the next. Ten bookmarked repos teach you nothing. One finished project teaches you a lot.
 
 

Shittu Olumide is a software engineer and technical writer passionate about leveraging cutting-edge technologies to craft compelling narratives, with a keen eye for detail and a knack for simplifying complex concepts. You can also find Shittu on Twitter.


Get the FREE ebook 'KDnuggets Artificial Intelligence Pocket Dictionary' along with the leading newsletter on Data Science, Machine Learning, AI & Analytics straight to your inbox.

By subscribing you accept KDnuggets Privacy Policy


Get the FREE ebook 'KDnuggets Artificial Intelligence Pocket Dictionary' along with the leading newsletter on Data Science, Machine Learning, AI & Analytics straight to your inbox.

By subscribing you accept KDnuggets Privacy Policy

Get the FREE ebook 'KDnuggets Artificial Intelligence Pocket Dictionary' along with the leading newsletter on Data Science, Machine Learning, AI & Analytics straight to your inbox.

By subscribing you accept KDnuggets Privacy Policy

No, thanks!