Chapter 2, Level 1: Aggregate Functions Flashcards
The … function calculates the smallest value for the selected column.
min
Which ‘aggregate function’ statement will return the numerical sum of all values in one column or more?
SELECT sum(column_name) FROM table_name;
Which ‘aggregate function’ statement will return the total number of rows in a table, except for those with a null value?
SELECT count(column_name) FROM table_name;
Which functions (also known as aggregate functions) only work if the columns contain numbers?
min
max
sum
avg
Which ‘aggregate function’ statement will return the numerical average of all values in one column or more?
SELECT avg(column_name) FROM table_name;
Which ‘aggregate function’ statement will return the total number of rows in a table?
SELECT count(*) FROM table_name;
True or false:
When using the ‘count(*)’ function statement, rows with ‘null’ values will be returned as well.
True.
If you wanted to know the lowest and highest numerical values of a column, which statement would return these values?
SELECT min(column_name), max(column_name) FROM table_name;
The … function calculates the largest value for the selected column.
max
Which ‘aggregate function’ statement will return the smallest numerical value in one column or more?
SELECT min(column_name) FROM table_name;
Which ‘aggregate function’ statement will return the largest numerical value in one column or more?
SELECT max(column_name) FROM table_name;
You have one column called Cost and another column which contains several different categories (or groups) called Products.
Give an example of a statement which will filter data in a table, to find the total cost of specific groups within the Products column.
SELECT column_name, sum(column_name)
FROM table_name
GROUP BY column_name
How can we filter data in a table to find the ‘total cost, lowest value, highest value or average’ of a specific group?
SELECT column_name1, aggregate_function(column_name2)
FROM table_name
GROUP BY column_name1
What does the HAVING clause do?
The HAVING clause can be used to only list groups that have more than one row associated with them.
Give an example of a SQL statement with a HAVING clause.
SELECT column_name, sum(column_name)
FROM table_name
WHERE column_name operator value (optional)
GROUP BY column_name
HAVING aggregate_function (column_name) operator value;