sqlcmd.net validated sql reference
beginner aggregation MySQL MariaDB SQL Server PostgreSQL SQLite

Calculate Averages With AVG

Compute the arithmetic mean of numeric values across matching rows.

Docker-validated Not currently validation-green

Average a set of review scores

This example uses values whose average is exactly 4, avoiding engine-specific decimal display differences.

Rows loaded before the example query runs.
Setup
CREATE TABLE reviews (id INT, score DECIMAL(4, 2));

INSERT INTO
  reviews (id, score)
VALUES
  (1, 4.00),
  (2, 5.00),
  (3, 3.00);
Shared across supported engines.
SQL
SELECT
  AVG(score) AS average_score
FROM
  reviews;
Returned rows for the shared example.
average_score
4

The same dataset and exact average validate cleanly across all engines.

Where this command helps.

  • calculating average order value or score
  • summarizing typical values in a filtered dataset

What the command is doing.

AVG(column) returns the arithmetic mean of the non-null values in a numeric column. It is useful for reporting on average order values, scores, durations, or prices.