mariadb-aggregate-functions

Documents MariaDB aggregate functions with signatures, NULL semantics, and common misuse corrections.

28|115|Updated Jan 28, 2025
One-click install
npx skills add https://github.com/mariadb-corporation/mariadb-docs --skill mariadb-aggregate-functions-mariadb-corporation
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: mariadb-aggregate-functions
Source: https://github.com/mariadb-corporation/mariadb-docs/tree/main/agent-skills/granular/functions/mariadb-aggregate-functions
Command: npx skills add https://github.com/mariadb-corporation/mariadb-docs --skill mariadb-aggregate-functions-mariadb-corporation

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing correct aggregation queries in MariaDB requires knowing subtle behaviors like NULL skipping, GROUP_CONCAT truncation, and population versus sample statistics, which are easy to get wrong without a reliable reference. ## Core Features & Use Cases - Complete Function Catalog: Lists all 16 built-in aggregate functions (COUNT, SUM, AVG, MIN, MAX, GROUP_CONCAT, BIT_AND/OR/XOR, STD/STDDEV family, VARIANCE family) with signatures and one-line semantics. - Misconception Corrections: A table of common LLM and developer mistakes mapped to the correct MariaDB behavior, such as COUNT(*) versus COUNT(expr) and GROUP_CONCAT truncation at group_concat_max_len. - Use Case: When writing a report query that rolls up sales by region, consult this reference to choose between STDDEV_POP and STDDEV_SAMP, handle empty-set NULL results, and avoid silent ONLY_FULL_GROUP_BY bugs. ## Quick Start Ask the AI to write a MariaDB query that groups orders by customer and concatenates their product names with GROUP_CONCAT, using this skill for correct syntax and NULL handling.

Frequently Asked Questions about mariadb-aggregate-functions

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I use GROUP_CONCAT in MariaDB with ordering and separators?▼

GROUP_CONCAT accepts DISTINCT, ORDER BY, SEPARATOR, and LIMIT inside the call, for example GROUP_CONCAT(DISTINCT x ORDER BY y SEPARATOR '; ' LIMIT 10). The default separator is a comma, and output is truncated at group_concat_max_len (default 1 MB).

What is the difference between COUNT(*) and COUNT(column) in MariaDB?▼

COUNT(*) counts all rows including those with NULLs, while COUNT(expr) counts only non-NULL values of the expression. COUNT(DISTINCT expr) counts distinct non-NULL values, so all three can return different results on the same column.

Does MariaDB STDDEV return sample or population standard deviation?▼

STD, STDDEV, and STDDEV_POP all return the population standard deviation (dividing by N). For the sample standard deviation (dividing by N-1), use STDDEV_SAMP; similarly VAR_SAMP gives sample variance.

Why does my MariaDB GROUP BY query return arbitrary values?▼

MariaDB's default sql_mode does not include ONLY_FULL_GROUP_BY, so selecting non-grouped columns runs without error and returns an arbitrary row's value per group. Add the column to GROUP BY or enable ONLY_FULL_GROUP_BY to make it an error.

What do MariaDB aggregates return on an empty result set?▼

On no matching rows, SUM, AVG, MIN, MAX, GROUP_CONCAT, and the STDDEV/VAR family return NULL; only COUNT returns 0. All aggregates except COUNT(*) skip NULL rows during calculation.

Can MariaDB aggregate functions be used as window functions?▼

Most aggregates work with OVER(), including COUNT, SUM, AVG, MIN, MAX, BIT_*, and the statistics family. However, SUM and AVG with DISTINCT cannot be window functions, and neither can JSON_ARRAYAGG or JSON_OBJECTAGG.