One Pager Cheat Sheet
- SQL provides a range of aggregate functions to compute single values from the data collected in a given set of input values, such as
AVG()
,COUNT()
,MIN()
,MAX()
, andSUM()
, while usually ignoring null values. - The
COUNT()
aggregate function returns the number of not null rows in a given column or the entire table and by using the keywordDISTINCT
in front of the column name, unique values can be counted. - The
sum()
aggregate function calculates the sum of all values in a numerical column, and its syntax looks likeSELECT SUM(column) FROM table WHERE condition;
. - We cannot use SUM() to calculate the sum of
date
data type values since it is only applicable to columns containing numerical values. - The
AVG()
function is used to calculate the average of numerical values in a specific column, while ignoring null values. - The
min()
andmax()
aggregations are used to return the minimum and maximum values of a specific column for several different data types. - Using
COUNT
,MIN
,MAX
,AVG
, andSUM
aggregate functions, we can query thePerson
table to find out thetotal number of customers
,date of the first and last order
,average age of the customers
, andtotal number of items ordered
. - The
MIN()
aggregate function returns the smallest value in the "City" column of the "Person" table, which is Berlin.