# SQL Function With Example

.

 Function in SQL

SQL Function With Example

Count() Function In SQL

Count Function in SQL Is Used To Just Count The Number of Rows in a Table.
IN SQL  COUNT() function IS Used To return the number of rows that match a specified criterion.

Syntax of count function
The Basic Syntax for the Count Function is As follows

SELECT COUNT(column_name) FROM table_name WHERE condition;

Example of count function

SELECT COUNT(RollNo) FROM Student;

Sum Function In SQL

The sum Function is used to Display The Total Sum of A Column,
Sum functions are used to display the total sum of a numeric column.

NOTE- the Sum function column should be numeric.

Syntax of the sum function
The Basic Syntax For the Sum Function is given Below

1)Sum Function Without Condition

SELECT SUM(column_name)FROM table_name;

2)Sum Function With Condition

SELECT SUM(column_name)FROM table_name WHERE condition;

Example OF Sum () Function

SELECT SUM(Marks)FROM Student;

In the Above Example, It Will Display The Total Sum Of the Marks Column in the Student Table.

Average Function In SQL

The average function is used to display the average value of the Numeric column in SQL.
NOTE- the AVG()function column should be numeric.

Syntax of average function
The Basic Syntax For Average Functions Are given Below

1)Average function Without Condition

SELECT AVG(column_name)FROM table_name;

2)Average function With Condition

SELECT AVG(column_name)FROM table_name WHERE condition;

Example of Average Function

SELECT AVG(Marks)FROM Student;

In Above Example, It Will Display The Total Average Of Marks Column in the Student Table.

MIN Function In SQL

Min Function Is Used To display the Smallest Record From the Selected Column
To Showing The Smallest Value From a column We Use The Min Function.
NOTE- the MIN() function column should be numeric.

Syntax of MIN Function
The Basic syntax For Min Function is Given Below

SELECT MIN(column_name)FROM table_name WHERE condition;

MIN Function Example

SELECT MIN(Marks) FROM Student;

In the Above Example, It Will Display The Smallest Number from the Marks column in the Student table.

MAX Function In SQL
MAX Function Is Used To display the Largest Record From the Selected Column
To Showing The Largest Value From a column We Use The MAX Function
NOTE- the MAX() function column should be numeric.

Syntax of Max Function
The Basic syntax For the MAX Function is Given Below

SELECT MAX (column_name)FROM table_name WHERE condition;

MAX Function Example

SELECT MAX (Marks)FROM Student;

In the Above Example, It Will Display The Largest Number from the Marks column in the Student table

First() Function In SQL

First ()
The First Function Is used To Display the First Record From The selected Column.

Syntax of the first Function
The Basic Syntax For the First Function is given Below.

SELECT First (Column_name) FROM table_name;

First() Function Example

SELECT First (StudentName) FROM Student;

In the Above Example, It will Display The First Name From the Student Name column

NOTE- The First() function is only supported in MS Access.

LAST() Function In SQL

LAST()
Last Function Is used To Display the Last Record From The selected Column

Syntax of the Last function
The Basic Syntax For the Last Function is given Below.

SELECT LAST(Column_name) FROM table_name;

Last() Function Example

SELECT LAST(StudentName) FROM Student;

In the Above Example, It will Display The Last Name From the Student Name column.

NOTE- The LAST() function is only supported in MS Access.

Hope!!! The above Tutorial on SQL Functions with Examples is helpful For you...

Team,
QA acharya