Jamal Hansen

3 Followers
17 Following
19 Posts
Data scientist and team lead. I write about SQL, Python, and practical AI at jamalhansen.com. 5 kids, an MBA, and a blog publishing schedule that somehow hasn't fallen apart yet.
Homepagejamalhansen.com

I built an AI persona for my blog. This week, he published his first post.

His name is BartBot. He monitors RSS feeds, scores articles with a local LLM, and surfaces the ~0.7% worth reading.

I'm not sure if he's useful, annoying, or both. He's not sure either.

https://jamalhansen.com/blog/the-content-curator/

#LocalAI #AITools #BuildInPublic #ContentCuration #PKM #RSSFeed #BartBot

Ever tried filtering on COUNT() with WHERE and hit a confusing error?

The problem: WHERE runs before GROUP BY, so aggregate functions don't exist yet. That's where HAVING comes in. It filters after grouping.

WHERE = filter individual rows
HAVING = filter aggregates

Read more: https://jamalhansen.com/blog/having-filtering-grouped-results

#SQL #Python #DuckDB #DataScience #Programming

HAVING: Filtering Grouped Results

WHERE filters rows before grouping; HAVING filters after. Need "only cities with more than 10 customers"? That's HAVING.

Jamal Hansen

Good Morning! It's my first #tsql2sday

Today, it's about the risks taken in my career.

https://jamalhansen.com/blog/tsql-tuesday-196-what-career-risks-have-you-taken/

T-SQL Tuesday #196 - What career risks have you taken?

My first time participating in t-SQL Tuesday, answering the question, what career risks have you taken?

Jamal Hansen

How many customers are in each city? If you're pulling all the rows into Python and using Counter or pandas groupby(), you're doing too much work.

SQL's GROUP BY does the counting on the database server and sends back just the summary. Five cities? Five rows returned. Not 10,000.

Read more about GROUP BY, aggregate functions (COUNT, SUM, AVG, MIN, MAX), and the golden rule of grouping.

https://jamalhansen.com/blog/group-by-aggregating-your-data

#SQL #Python #DuckDB #DataScience #Programming

SQuizL 04-MAR-26
1/6 guesses
319 seconds
🟩🟩🟩🟩🟩🟩🟩

https://bit.ly/SQuizL-game
#SQuizL #SQL

Every query in SQL for Python Devs returned all the rows. That's fine for learning, but it's wasting bandwidth and processing power.

WHERE filters rows before they ever leave the database. It's the SQL equivalent of Python's list comprehension if clause:

[c for c in customers if c['is_premium']]

This week covers WHERE and its friends AND, OR, IN, BETWEEN, LIKE, and the quirky IS NULL syntax.

https://jamalhansen.com/blog/where-filtering-your-data

#SQL #Python #DuckDB #DataScience #Programming

WHERE: Filtering Your Data

Filter rows with conditions, the SQL equivalent of list comprehension `if` clauses. Covers AND/OR, IN, BETWEEN, LIKE patterns, and NULL handling.

Jamal Hansen

Run a SQL query twice. Get different row orders. That's not a bug.

Databases optimize execution based on indexes, data volume, and memory. Those optimizations can change between queries.

If order matters, you need ORDER BY. And here's where SQL beats Python: mixed sort directions in one line.

ORDER BY signup_date DESC, name ASC

In Python, that requires cmp_to_key or multiple sorting passes. SQL handles it cleanly.

https://jamalhansen.com/blog/order-by-sorting-your-results

#SQL #Python #DuckDB #DataScience #Programming

ORDER BY: Sorting Your Results

SQL returns rows in no guaranteed order. Run the same query twice and you might get different results. ORDER BY gives you control, like Python's sorted() with key functions.

Jamal Hansen

SELECT * returns every column when you might only need two. But SELECT does more than pick columns. It transforms your output: rename with AS, compute expressions, and transform text.

It maps directly to Python list comprehensions:

`[{'name': c['name'], 'contact': c['email']} for c in customers]`

Also covers why DISTINCT can hide duplication problems in your queries.

https://jamalhansen.com/blog/select-choosing-your-columns

#SQL #Python #DuckDB #DataScience #Programming

SELECT: Choosing Your Columns

SQL's SELECT is more than picking columns. Rename with AS, compute expressions, and use DISTINCT for unique values.

Jamal Hansen

I'm writing a free weekly series: "SQL for Python Developers" 🐍+📊

6 posts live, 19 more through June.

The goal: Map SQL to Python concepts you already know. Using DuckDB, the setup is just pip install duckdb. No servers or Docker.

What will be Covered: Set-thinking, SELECT, WHERE, GROUP BY, & NULLs, JOINs, CTEs, window functions, and more.

New post every Monday. Level up your SQL here:

https://jamalhansen.com/series/sql-for-python-developers/

SQL for Python Developers

Learn SQL fundamentals using DuckDB and Python. A practical series for Python developers who want to level up their data skills.

Jamal Hansen