SQL Functions
SQL Functions
SQL provides many built-in functions to perform operations on data. These functions are useful
while performing mathematical calculations, string concatenations, sub-strings etc. SQL
functions are divided into two categories,
1. Aggregate Functions
2. Scalar Functions
Aggregate Functions
These functions return a single value after performing calculations on a group of values.
Following are some of the frequently used Aggregrate functions.
AVG() Function
Average returns average value after calculating it from values in a numeric column.
COUNT() Function
Count returns the number of rows present in the table either based on some condition or without
condition.
count(name)
2
Example of COUNT(distinct)
count(distinct salary)
4
FIRST() Function
first(salary)
9000
LAST() Function
LAST function returns the return last value of the selected column.
last(salary)
8000
MAX() Function
MAX function returns maximum value from selected column of the table.
MAX(salary)
10000
MIN() Function
MIN function returns minimum value from a selected column of the table.
MIN(salary)
6000
SUM() Function
SUM(salary)
41000
Scalar Functions
Scalar functions return a single value from an input value. Following are some frequently used
Scalar Functions in SQL.
UCASE() Function
Syntax of UCASE,
Result is,
UCASE(name)
ANU
SHANE
ROHAN
SCOTT
TIGER
LCASE() Function
LCASE(name)
anu
shane
rohan
scott
tiger
MID() Function
MID function is used to extract substrings from column values of string type in a table.
ROUND() Function
ROUND function is used to round a numeric field to number of nearest integer. It is used on
Decimal point values.
ROUND(salary)
9001
8001
6000
10000
8000