Saturday, March 01, 2008

Using Statistic Function on SQL Query

In SQL Query, we can use statistic function or math function to customize our query design.
some of statistic or math function can be use on SQL query, are:

AVG -> return average of value on behalf column.
COUNT -> return how many of the objects on behalf column
MAX -> return the highest value on behalf column
MIN -> return the lowest value on behalf column
SUM -> return the summary of object on behalf column


*************************************************

EmployeeID Salary
----------- -------
31000 800000
31000 850000
31000 900000
32000 775000
32000 800000
32000 825000

*************************************************

Example AVG:

Select MAX(EmployeeID) as ID, AVG(Salary) as Salary
From PayrollTable
Group by Employee ID

Result: The Average of Salary Field based on EmployeeID
***********************************

ID Salary
----- ------
31000 850000
32000 800000

***********************************

Example COUNT:
Select MAX(EmployeeID) as ID, COUNT(Salary) as Salary
From PayrollTable
Group by Employee ID

Result: The Count Record of Salary Field based on EmployeeID
***********************************

ID Salary
----- ------
31000 3
32000 3

***********************************

Example MAX:
Select MAX(EmployeeID) as ID, MAX(Salary) as Salary
From PayrollTable
Group by Employee ID

Result: The Maximun Value of Salary Field based on EmployeeID
***********************************

ID Salary
----- -------
31000 900000
32000 825000

***********************************

Example MIN:
Select MAX(EmployeeID) as ID, MIN(Salary) as Salary
From PayrollTable
Group by Employee ID

Result: The Minimun Value of Salary Field based on EmployeeID
***********************************

ID Salary
----- -------
31000 800000
32000 775000

***********************************

Example SUM:
Select MAX(EmployeeID) as ID, SUM(Salary) as Salary
From PayrollTable
Group by Employee ID

Result: The Minimun Value of Salary Field based on EmployeeID
***********************************

ID Salary
----- -------
31000 2250000
32000 2400000

***********************************

that's all from me...

enjoy it...




0 comments:

Google

Microsoft News for ADO .NET:

Our Email Address:

blog.programming@gmail.com