SQL also offers a bunch of built-in functions that come in handy when trying to obtain numeric totals and averages of specific fields. The first of these is the very useful COUNT() function, which counts the number of records in the result set and displays this total. Consider the following example, which displays the total number of records in the "videos" table: This comes in very handy when you need to quickly calculate the total number of records in a table. The SUM() function calculates the sum of the values in the result set, while the AVG() function calculates the average. For example, if you wanted to calculate the average grade in math, physics and literature, you could use a query like this: You can identify the smallest and largest value in a specific column with the MIN() and MAX() functions - the following queries display the lowest and highest grade in math respectively.
This article copyright Melonfire 2001. All rights reserved.
blog comments powered by Disqus |