SQL function examples

SQL Statement Syntax Example Statement Example Result or Description
SELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name
HAVING aggregate_function(column_name) operator value

Use HAVING to specify conditions when using SQL aggregate functions. (Use instead of WHERE for aggregate functions.)

SELECT AVG(column_name) FROM table_name;

Use AVG() to calculate the average value of the non-null records in the specified column.

SELECT COUNT(column_name) FROM table_name;
select ApplicationName as Name,
count(*) as Count from Event
where WhenOccurred >= DateFunc('now', '-30')
and EventType='Cloud.Saas.Application.AppLaunch'
group by name order by count desc

COUNT (Column_name) returns the number of non-null values in the specified column.

COUNT (*) returns the number of records in a table.

COUNT (Distinct column_name) returns the number of distinct values in the specified column.

SELECT MAX(column_name)FROM table_name;
SELECT MIN(column_name)FROM table_name;

Use MAX() to return the maximum value of all values in the group.

use MIN() to return the minimum, non-null value of all values in the group. The results include null values only if there are no non-null values.