. 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 matches a specified criterion.

Count()Syntax
The Basic Syntax for Count Function is As follows

SELECT COUNT(column_name) FROM table_name WHERE condition;

EXAMPLE-

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.

Sum() Syntax
The Basic Syntax For 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 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.

Avg() Syntax
The Basic Syntax For Average Function 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 Smallest Record From Selected Column
To Showing The Smallest Value From a column We Use The Min Function.
NOTE- the MIN() function column should be numeric.

MIN()Syntax
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 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 Largest Record From Selected Column
To Showing The Largest Value From a column We Use The MAX Function
NOTE- the MAX() function column should be numeric.

MAX ()Syntax
The Basic syntax For MAX Function is Given Below

SELECT MAX (column_name)FROM table_name WHERE condition;

MAX Function Example

SELECT MAX (Marks)FROM Student;

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

First() Function In SQL

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

First () Syntax
The Basic Syntax For First Function is given Below.

SELECT First (Column_name) FROM table_name;

First() Function Example

SELECT First (StudentName) FROM Student;

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

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

LAST() Function In SQL

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

LAST() Syntax
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 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

.