Functions

A function is nothing but a sub program or a module which can written for achieving a particular task.

OR

A function is a readymade formula, which takes values as input and returns values as output.

OR

A function is a pre defined program segment that carries specific and well-defined task.

Classifications of Functions:

1. Scalar or Single-Valued Functions
2. Group or Aggregate Functions

Scalar Valued Functions:

These functions take single value as input and returns single value as output.

Classification of Scalar Valued Functions:

1. Mathematical functions
2. String Functions
3. Date & Time Functions

Mathematical Functions:

ABSOLUTE: It returns the ABSOLUTE value of N

->Select ABS (-10.65)
->Select ABS (18.67)

Power (M, N): It returns the Power N Value

->Select Power (3, 2) = 9
->Select Power (6, 2) =36

String Functions:

ASCII (CH): It returns the ASCII value of given character.
-> Select ASCII (‘A’) =65
-> Select ASCII (‘a’) =97
-> Select ASCII (‘o’) =48
-> Select ASCII (‘ ’) =32

Date Functions:

Get DATE(): It returns the current date and time

-> Select GetDate ()

Aggregate or Group Functions:
These functions takes multiple values as input and returns single value as output, these includes
Max ()
Min ()
Sum ()
Avg ()
Count ()
Count_big ()

Based on the above table we will do some examples for Aggregate functions
Example: Select max (sal) as Hisal from emp
Hisal = 20000

Group by Clause:

This clause is used to divide the table into number of subgroups based on a specific column.

Syntax: select statement Group by column name
Share/Bookmark

No comments: