HomeBrainDump Page 5 - SQL: Functioning in the Real World
Minimum and Maximum - BrainDump
A couple of months or so ago, I began talking about SQL functions and what they're used for. This article picks up where I left off. It defines the two types of functions, and begins to explain them in great detail.
The Min(Column) and Max(Column) functions return the lowest and highest value in a column, respectively. If we wanted to see the highest pay rate in our Employees table, we would do the following:
Select Max(Salary) from Employees
This would return the value, $100,000. If we wanted to see the lowest salary, we would do this:
Select Min(Salary) from Employees
The result of this would be $12,000. Poor Ang Ree.
In Summation
Ha! I fooled you! You though this was the end of the article. Well you were wrong; I was using word play to trick your feeble mind.
You can use the Sum(Column) function to get a total of all the values in a column. If we wanted to know the annual salary of all of the employees in the Employee table, it would go a little something like this:
Select Sum(Salary) from Employees
This would add all of the values in the Salary column, resulting in the total: $342,000.
Well, that wraps it up for this part. In the next part we will cover the rest of the Aggregate Functions, and learn the Scalar functions as well. Look forward to seeing you.