Showing posts with label SQL SERVER FUNCTIONS. Show all posts
@@Functions in SQL SERVER
Posted on
Monday, 13 August 2012
by
SQL Developer


Posted in
Miscellaneous,
SQL SERVER FUNCTIONS
|
Leave a comment
AVG in SQL SERVER
Posted on
Friday, 20 April 2012
by
SQL Developer
AVG is an aggregate function which is used to obtain the average of the values in a particular column.
Syntax:
SELECT AVG(<Column Name>) from <Table Name>
Example:
We have a table with the following data in the table SALES.
In order find out the average price of items in the sales we should use AVG function.
QUERY:
SELECT AVG(PRICE) FROM SALES
Result Set:
Result set contains average of all the values in PRICE column.
Syntax:
SELECT AVG(<Column Name>) from <Table Name>
Example:
We have a table with the following data in the table SALES.
ITEM | PRICE |
ABC | 99.05 |
ABC1 | 110.99 |
ABC2 | 70.89 |
ABC3 | 100.99 |
ABC4 | 55.89 |
In order find out the average price of items in the sales we should use AVG function.
QUERY:
SELECT AVG(PRICE) FROM SALES
Result Set:
Result set contains average of all the values in PRICE column.


Posted in
SQL SERVER COMMANDS,
SQL SERVER FUNCTIONS
|
Leave a comment
MIN in SQL SERVER
by
SQL Developer
MIN is an aggregate function which is used to obtain the minimum value out of all the values in a particular column.
Syntax:
SELECT MIN (<Column Name>) from <Table Name>
Example:
We have a table with the following data in the table SALES.
In order find out the minimum price out of all the sales we should use MIN function.
QUERY:
SELECT MIN(PRICE) FROM SALES
Result Set:
Result set contains minimum value of all the values in PRICE column.
Syntax:
SELECT MIN (<Column Name>) from <Table Name>
Example:
We have a table with the following data in the table SALES.
ITEM | PRICE |
ABC | 99.05 |
ABC1 | 110.99 |
ABC2 | 70.89 |
ABC3 | 100.99 |
ABC4 | 55.89 |
In order find out the minimum price out of all the sales we should use MIN function.
QUERY:
SELECT MIN(PRICE) FROM SALES
Result Set:
Result set contains minimum value of all the values in PRICE column.


Posted in
SQL SERVER COMMANDS,
SQL SERVER FUNCTIONS
|
Leave a comment
MAX Function in SQL Server
by
SQL Developer
MAX is an aggregate function which is used to obtain the maximum value out of all the values in a particular column.
Syntax:
SELECT MAX (<Column Name>) from <Table Name>
Example:
We have a table with the following data in the table SALES.
In order find out the maximum price out of all the sales we should use MAX function.
QUERY:
SELECT MAX(PRICE) FROM SALES
Result Set:
Result set contains maximum value of all the values in PRICE column.
Syntax:
SELECT MAX (<Column Name>) from <Table Name>
Example:
We have a table with the following data in the table SALES.
ITEM | PRICE |
ABC | 99.05 |
ABC1 | 110.99 |
ABC2 | 70.89 |
ABC3 | 100.99 |
ABC4 | 55.89 |
In order find out the maximum price out of all the sales we should use MAX function.
QUERY:
SELECT MAX(PRICE) FROM SALES
Result Set:
Result set contains maximum value of all the values in PRICE column.


Posted in
SQL SERVER COMMANDS,
SQL SERVER FUNCTIONS
|
Leave a comment
SUM in SQL Server
by
SQL Developer
SUM is an aggregate function which is used to calculate the sum or total of values in a particular column.
Syntax:
SELECT SUM (<Column Name>) from <Table Name>
Example:
We have a table with the following data in the table SALES.
In order to count the total amount ( sum of the total prices) can be obtained by using SUM function.
QUERY:
SELECT SUM(PRICE) FROM SALES
Result Set:
Result set contains sum (total amount) of all the values in column PRICE.
Note:
Syntax:
SELECT SUM (<Column Name>) from <Table Name>
Example:
We have a table with the following data in the table SALES.
ITEM | PRICE |
ABC | 99.05 |
ABC1 | 110.99 |
ABC2 | 70.89 |
ABC3 | 100.99 |
ABC4 | 55.89 |
In order to count the total amount ( sum of the total prices) can be obtained by using SUM function.
QUERY:
SELECT SUM(PRICE) FROM SALES
Result Set:
Result set contains sum (total amount) of all the values in column PRICE.
Note:
- Sum function can be applied only on int , float , decimal , money data types.
- SUM Function ignores the NULL values in the columns.


Posted in
SQL SERVER COMMANDS,
SQL SERVER FUNCTIONS
|
Leave a comment
COUNT in SQL SERVER
by
SQL Developer
COUNT is one of the most frequently used aggregate function in SQL SERVER.
As the indicated it counts the number of rows or records in the table.
Generally COUNT function is used to find out the number of rows in a table.
Syntax for the COUNT functions is:
SELECT COUNT(*) FROM <Table Name>
SELECT COUNT(1) FROM <Table Name>
Example:
Lets find out the number of rows in STUDENTS table using COUNT.
Query:
SELECT COUNT(*) FROM STUDENTS
SELECT COUNT(1) FROM STUDENTS
Both of the above queries will return the same result.
Result Set:
As the indicated it counts the number of rows or records in the table.
Generally COUNT function is used to find out the number of rows in a table.
Syntax for the COUNT functions is:
SELECT COUNT(*) FROM <Table Name>
SELECT COUNT(1) FROM <Table Name>
Example:
Lets find out the number of rows in STUDENTS table using COUNT.
Query:
SELECT COUNT(*) FROM STUDENTS
SELECT COUNT(1) FROM STUDENTS
Both of the above queries will return the same result.
Result Set:


Posted in
SQL SERVER COMMANDS,
SQL SERVER FUNCTIONS
|
Leave a comment
Aggregate Functions in SQL Server
by
SQL Developer
Aggregate functions perform the calculation on the data and will return a single value as the out put.
In real time aggregate functions are used to calculate the minimum, maxmimum and average statistics.
HAVING Clause is mostly used to operate along with the aggregate functions.
Most frequently used Aggregate functions are:
Less frequently used aggregate functions are:
In real time aggregate functions are used to calculate the minimum, maxmimum and average statistics.
HAVING Clause is mostly used to operate along with the aggregate functions.
Most frequently used Aggregate functions are:
Less frequently used aggregate functions are:
- CHECKSUM
- COUNT_BIG
- CHECKSUM_AGG
- BINARY_CHECKSUM
- GROUPING
- VAR
- VARP
- STDEV
- STDEVP


Posted in
SQL SERVER COMMANDS,
SQL SERVER FUNCTIONS
|
Leave a comment