GSAK (Geocaching Swiss Army Knife)
 

Contents - Index


SQL - Group By


Allows you to group data.

Syntax:

Group By fieldlist
 
fieldlist is a comma separated list of one or more fields that you want to grouping to be applied.

Example to get the totals by cache type (but only if at least 10 in total):
 

$status = dbtosql("caches","Code,Name,CacheType,Container,Difficulty,Terrain","$_Install\macros\caches.txt","")
$status = sql("select CacheType, count(CacheType) as Total from caches Group By CacheType having total > 10","")
$html = sqltohtml($status,"Cache Summary","Y")

  

 
Note: Any field that you want to group by, must also be included in the select clause.
 
Aggregate functions

You can apply the count, sum, avg (but see quirks) , max, min, stddev function to an input field. When you use these functions without a GROUP BY clause, the resultset will contain only one row.

For example,  to get the total number of traditional caches (using the already created caches table from the example above)
 

$TotalTraditional = val(sql("select count(cachetype) from caches where CacheType = 'T'",""))



Copyright 2004-2008 CWE Computer Services  
Privacy Policy Contact