060. Max, Min, Sum

 

Of these, I’ve used Max and Sum quite a bit. But Min, not so much.

 

The Max() function returns the maximum value of a given column.
Create Table tblMax (Column1 Decimal(18,2))
Go
Insert tblMax Values (6)
Insert tblMax Values (2)
Insert tblMax Values (Null)
Insert tblMax Values (21)

 

Select Max(Column1) From tblMax
This returns: 21.00

 

Similarly, Min returns the minimum value of the column:
Select Min(Column1) From tblMax
This returns: 2.00

 

Notice how Null is ignored.

 

The Sum() function gives the sum of a column.
Select Sum(Column1) From tblMax
This returns: 29.00

 

In all of these, Where can be used to do some filtering.