PC Books || Educational Software || Magazines
Amazon: Books-CA || Software-CA || Books-UK || Software-UK

HTML | Javascript | ASP | PHP | VBScript | SQL | Hardware | PC FAQ| WinXP|

Learn to Build, Upgrade, or Repair your Computer Ebook + PC Safety 101 Reasonably priced web development & hosting
SQL Basics
Create Tables
Data Type
Delete/Modify Table
Add Rows
Create Sequence
Single-Row Function
Group Functions
Create Views
Books @
CA Amazon
UK Amazon
US Amazon

  :: Home
PC Topics
  :: Build A PC
  :: Windows XP
  :: PC Help
  :: HTML
  :: JavaScript
  :: ASP
  :: PHP
  :: VBScript
  :: SQL
  :: Code/Scripts
  :: Forum
  :: Links
  :: Contact us
  :: Tell A Friend
  :: In Somali
Web Articles
  Top Web Hosting
Online Card Payment Guide
  Domain name
registration & buying guide
a website online guide
  Search Engine
submission & optimization tips
Netfirms Web Hosting
Free trial
Quality business correspondence.
Yahoo! Search Marketing

Group Functions

An SQL group function or aggregate functions performs an operation on a group of rows and returns a single result.  You may want retrieve group of item-prices and return total-price.  This type of scenario is where you would use a group function.  The following table is summary of some SQL group functions & query examples.
Function DescriptionQuery Example
AVG(fieldname)Returns average value of a columnSELECT avg(price)FROM inventory;
Returns number of items in table or queried itemsSELECT count(product_id)FROM product;
SELECT count(*) FROM product;
Returns maximum value of a column SELECT max(price)FROM inventory;
Returns minum value of a column SELECT min(price)FROM inventory;
Returns total value of a column SELECT sum(price)FROM inventory;
To use a group function in a SQL query, list the function name followed by numeric column name within parentheses.  AVG averages the column, COUNT counts the number of items, MAX returns maximum number of the column, and MIN returns minimum number of the column.
The following is query to retrieve total price, average price, maximum price, and minimum price from the table "product" assuming the product table has the following values.
Product IDNameDescriptionPriceCost
100000000PrinterInkjet 300 colour Printer12080
100000001Printer1220CXI Inkjet Printer 200130
100000002PrinterPhoto 890 Injet Printer 250200
100000003PrinterPhoto 890 Injet Printer 300270
SQL statements.

SELECT sum(price)
FROM product;

This statement will return the total amount for the column price which is 870.
SELECT avg(price)
FROM product;

This statement will return the average amount for the column price which is 870/4 or 217.50.
SELECT max(price)
FROM product;

This statement will return the maximum amount for the column price which is 300.
SELECT min(price)
FROM product;

This statement will return the minimum amount for the column price which is 120.
SELECT count(*)
FROM product;

This statement will return the number of items in table which is 4.

GROUP BY Clause with Group Functions
Group By is used to categorize the retrieved data.  For example, you may wight want list sales of each product identified by product id.  To do this, the following is Group By example that lists
Single-row functions Joints
Listed @ - The Consumer Rated Web Directory
PC Articles
  Computer Safety
prevent viruses & Spyware