---
title: "What is function in Database? explain some function like Sum(), Count(), Max(), Min(), AVG() with example."  
description: "What is function in Database? explain some function like Sum(), Count(), Max(), Min(), AVG() with example."  
author: "Ethan Karla"  
published: 2021-09-14  
updated: 2023-04-12  
canonical: https://answers.mindstick.com/qa/93945/what-is-function-in-database-explain-some-function-like-sum-count-max-min-avg-with-example  
category: "database"  
tags: ["database", "database design"]  
reading_time: 4 minutes  

---

# What is function in Database? explain some function like Sum(), Count(), Max(), Min(), AVG() with example.

What is [function](https://www.mindstick.com/articles/43970/purchase-suitable-wedding-dresses-for-your-wedding-function) in [Database](https://www.mindstick.com/articles/100/windows-service-to-update-record-from-one-database-to-another-after-certain-interval-of-time)? [explain](https://yourviews.mindstick.com/view/86025/content-created-for-humans-not-for-bots-explain-this-statement) some function like [Sum](https://www.mindstick.com/interview/1418/what-is-the-way-for-summing-up-a-column-in-a-table-in-microsoft-access-database)(), Count(), [Max](https://www.mindstick.com/articles/1155/count-max-min-function-in-excel)(), [Min](https://www.mindstick.com/interview/524/name-the-numeric-constants-representing-max-min-values)(), [AVG](https://www.mindstick.com/articles/445/aggregate-function-in-sql-server)() with example.

## Answers

### Answer by Ashutosh Kumar Verma

## Function in SQL Server-

A function is a set of code that perform specific task. There are some predefined function in SQL Server are as follow-

COUNT(), AVG(), SUM(), MAX(), MIN().

## SQL COUNT(), AVG() and SUM() functions –

## COUNT() –

The SQL COUNT () function is used to find the number of rows in a column of a table.

Syntax-

SELECT COUNT(column_ name) FROM table_name WHERE condition;

## AVG() function-

The SQL AVG() function is used to find the Average of numerical column values of a table.

Syntax-

SELECT AVG(column_name) FROM table_name WHERE condition;

## SUM() function –

The SQL SUM() function is used to find the sum of numerical column values in a table.

Syntax-

SELECT SUM(column_name) FROM table_name WHERE condition;

We have a database table “TeacherDetails”-

![What is function in Database? explain some function like Sum(), Count(), Max(), Min(), AVG() with example.](https://answers.mindstick.com/questionanswer/69bbb975-e8d3-4a36-9e53-f9e874780f85/images/561007fa-777a-440d-be86-f61245825a4a.png)

## Example-

**COUNT()-** The following statement is to find the number of row in a column of ‘TeacherDetails’ table.

## select count(stuCourse) from TeacherData;

![What is function in Database? explain some function like Sum(), Count(), Max(), Min(), AVG() with example.](https://answers.mindstick.com/questionanswer/69bbb975-e8d3-4a36-9e53-f9e874780f85/images/93927bf2-d39d-437d-8298-7658210aac23.png)

**AVG()-** The following statement is to find the Average of numerical column values of ‘TeacherDetails’ table.

## select avg(Salary) from TeacherData;

![What is function in Database? explain some function like Sum(), Count(), Max(), Min(), AVG() with example.](https://answers.mindstick.com/questionanswer/69bbb975-e8d3-4a36-9e53-f9e874780f85/images/fc6476ea-2801-4b05-86fa-f3a5196bee7c.png)

**SUM()-** The following statement is to find the sum of the numerical column values in table ‘TeacherDetails’.

## select sum(Salary) from TeacherData;

![What is function in Database? explain some function like Sum(), Count(), Max(), Min(), AVG() with example.](https://answers.mindstick.com/questionanswer/69bbb975-e8d3-4a36-9e53-f9e874780f85/images/2b90b76a-c3da-4612-9ff8-a4d808add7e7.png)

\

## SQL MIN and MAX – \

The SQL function MIN() and MAX() is to find the minimum and maximum values form database table.

The **MIN()** function is used to find the minimum value from table.

The **MAX()** function is used to find the maximum value from table.

**MIN(** **)** Syntax-

SELECT MIN(column_name) FROM table_name WHERE condition;

**MAX()** Syntax-

SELECT MAX(column_name) FROM table_name WHERE condition; MAX() function

## Example-

- Let have a table ‘TeacherDetails’.

![What is function in Database? explain some function like Sum(), Count(), Max(), Min(), AVG() with example.](https://answers.mindstick.com/questionanswer/69bbb975-e8d3-4a36-9e53-f9e874780f85/images/e586b1c6-6253-4e7c-a6e9-2779cbc32f96.png)

**MAX()-** Follow the statement to find the maximum value from ‘TeacherDetails’ table.

## select max(Salary) from TeacherData;

![What is function in Database? explain some function like Sum(), Count(), Max(), Min(), AVG() with example.](https://answers.mindstick.com/questionanswer/69bbb975-e8d3-4a36-9e53-f9e874780f85/images/19628e13-a937-4ed5-8b15-b4b8755e55c4.png)

To find the record which has maximum Salary then you can use the following statement.

## select * from TeacherData where Salary=(select max(Salary) from TeacherData);

![What is function in Database? explain some function like Sum(), Count(), Max(), Min(), AVG() with example.](https://answers.mindstick.com/questionanswer/69bbb975-e8d3-4a36-9e53-f9e874780f85/images/3b732cc4-0d76-407e-8c7d-a78177f964da.png) **\**

**MIN()-** The following statement is used to find the minimum Salary from ‘TeacherDetails’ table.

## select min(Salary) from TeacherData;

![What is function in Database? explain some function like Sum(), Count(), Max(), Min(), AVG() with example.](https://answers.mindstick.com/questionanswer/69bbb975-e8d3-4a36-9e53-f9e874780f85/images/18b92c37-9a06-4a03-ad10-b489f97f6682.png)

To find the record of that row which has minimum value is like as-

## select * from TeacherData where Salary =(select min(Salary) from TeacherData);

![What is function in Database? explain some function like Sum(), Count(), Max(), Min(), AVG() with example.](https://answers.mindstick.com/questionanswer/69bbb975-e8d3-4a36-9e53-f9e874780f85/images/5e8b0e4c-e48b-4728-ba3a-08bbe4c9d612.png)\

\

\

\

\

### Answer by Ravi Misra

> Count all the DISTINCT program names by program type and push number

```plaintext
SELECT COUNT(DISTINCT program_name) AS Count,
  program_type AS [Type]
FROM cm_production
WHERE push_number = @push_number
GROUP BY program_type
```

`DISTINCT COUNT(*)` will return a row for each unique count. What you want is [COUNT(DISTINCT <expression>)](http://msdn.microsoft.com/en-us/library/ms175997.aspx): evaluates expression for each row in a group and returns the number of unique, non-null values.


---

Original Source: https://answers.mindstick.com/qa/93945/what-is-function-in-database-explain-some-function-like-sum-count-max-min-avg-with-example

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
