> For the complete documentation index, see [llms.txt](https://gyansetu-sql.gitbook.io/sql-programming/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gyansetu-sql.gitbook.io/sql-programming/sql-select/sql-server-functions/sql-count-avg-and-sum-functions.md).

# SQL COUNT(), AVG() and SUM() Functions

The SQL COUNT(), AVG() and SUM() Functions

The COUNT() function returns the number of rows that matches a specified criteria.

The AVG() function returns the average value of a numeric column.

The SUM() function returns the total sum of a numeric column.

#### COUNT() Syntax

```sql
SELECT COUNT(column_name)
FROM table_name
WHERE condition;
```

#### AVG() Syntax

```sql
SELECT AVG(column_name)
FROM table_name
WHERE conditionSUM() Syntax
```

> #### SUM() Syntax

```sql
SELECT SUM(column_name)
FROM table_name
WHERE condition;
```

### Demo Database

&#x20;Below is a selection from the "Products" table in the Northwind sample database

![](https://826093633-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LS8lPNzCGPR5-DLbGXv%2F-LST9Ou2u55zTiUeQtOI%2F-LSTBsnZBb20AfBHg762%2Fimage.png?alt=media\&token=5d02fb11-b5a3-4794-b5d9-f97d208fc282)

### SUM()&#x20;

The following SQL statement finds the sum of the "Quantity" fields in the "OrderDetails" table:<br>

```sql
SELECT SUM(Quantity)
FROM OrderDetails;
```
