Sobes.tech
Middle

How does the GROUP BY operator handle NULL values?

sobes.tech AI

Answer from AI

The GROUP BY operator treats NULL values as a separate group. All rows with NULL in the grouping column are included in this single NULL group.

Example:

Suppose we have a products table with columns category (String) and price (double):

category price
Electronics 100
Electronics 200
NULL 50
Clothing 30
NULL 70

When executing the query:

SELECT category, AVG(price)
FROM products
GROUP BY category;

The result will be approximately:

category AVG(price)
Electronics 150.0
NULL 60.0
Clothing 30.0
How does the GROUP BY operator handle NULL values… - sobes.tech