Small. Fast. Reliable.
Choose any three.

About Sitemap Documentation Download License News Developers Support

## SQL As Understood By SQLite

### Aggregate Functions

The aggregate functions shown below are available by default. Additional aggregate functions written in C may be added using the sqlite3_create_function() API.

In any aggregate function that takes a single argument, that argument can be preceeded by the keyword DISTINCT. In such cases, duplicate elements are filtered before being passed into the aggregate function. For example, the function "count(distinct X)" will return the number of distinct values of column X instead of the total number of non-null values in column X.

avg(X) | Return the average value of all non-NULL X within a group. String and BLOB values that do not look like numbers are interpreted as 0. The result of avg() is always a floating point value even if all inputs are integers.
count(X) count(*) | The first form return a count of the number of times that X is not NULL in a group. The second form (with no argument) returns the total number of rows in the group.
group_concat(X) group_concat(X,Y) | The result is a string which is the concatenation of all non-NULL values of X. If parameter Y is the separator between instances of X. A comma (",") is used as the separator if Y is omitted.
max(X) | Return the maximum value of all values in the group. The usual sort order is used to determine the maximum.
min(X) | Return the minimum non-NULL value of all values in the group. The usual sort order is used to determine the minimum. NULL is only returned if all values in the group are NULL.
sum(X) total(X) | Return the numeric sum of all non-NULL values in the group. If there are no non-NULL input rows then sum() returns NULL but total() returns 0.0. NULL is not normally a helpful result for the sum of no rows but the SQL standard requires it and most other SQL database engines implement sum() that way so SQLite does it in the same way in order to be compatible. The non-standard total() function is provided as a convenient way to work around this design problem in the SQL language. The result of total() is always a floating point value. The result of sum() is an integer value if all non-NULL inputs are integers. If any input to sum() is neither an integer or a NULL then sum() returns a floating point value which might be an approximation to the true sum. Sum() will throw an "integer overflow" exception if all inputs are integers or NULL and an integer overflow occurs at any point during the computation. Total() never throws an exception.

This page last modified 2008/08/12 18:08:17 UTC