Aggregate and Mathematical functions

Aggregate function -performs a calculation on a set of values, and returns a single value.

Min-Returns the minimum value.
Max-
Returns the maximum value.
Count 
-Returns the Count value.
Sum-
Returns the Sum(Addition) value.
Avg-Returns the Average value.

Create Table Emp
(
Id Int Primary key Identity(1,1),
Name Varchar(50),
Salary Decimal(7,2),
Department nvarchar(50)
)
Go
Insert Into Emp (Name,Salary,Department) Values ('Amol',1252.62,'Account')
Insert Into Emp (Name,Salary,Department) Values ('Balu',1254.62,'Account')
Insert Into Emp (Name,Salary,Department) Values ('Chetan',54544.62,'IT')
Insert Into Emp (Name,Salary,Department) Values ('Dhurva',11141.62,'Account')
Insert Into Emp (Name,Salary,Department) Values ('Eknath',12125.62,'Account')
Insert Into Emp (Name,Salary,Department) Values ('shrinath',80000.62,'IT')
Insert Into Emp (Name,Salary,Department) Values ('Gaurav',41541.62,'IT')
Go
Select * from Emp

Select Count(*) As [Count] From Emp
Select min(Salary) [Min] From Emp
Select Max(Salary) [Max] From Emp
Select Sum(Salary) [Sum] From Emp
Select Avg(Salary) [Avg] From Emp

output
Aggregate






















Group by Statement

SELECT Department,
Count(Id) [Count],
Min(Salary) [Min],
Max(Salary) [Max],
Sum(Salary) [Sum],
AVG(Salary) [Avg]
FROM Emp
Group By Department

Group by






Mathematical Functions

Select Sqrt(9)--3
Select Square(3)--9
Select Power(2,4)--16
Select Round(6.25325,3)--6.25300
Select Round(6.25375,0)--6.00000
Select Round(6.151,0,0)--6.000
Select Ceiling(6.25)--7
Select Ceiling(6.85)--7
Select floor(6.25)--6
Select floor(6.85)--6
Select Rand()*1000--783.774493670302
select sin(30)-- -0.988031624092862
Select cos(30)--0.154251449887584
Select tan(30)-- -6.40533119664628



Comments