Shared Flashcard Set

Details

Aggregate Functions - SQL
codecademy Aggregate Functions - Cheat Sheet
17
Computer Science
Not Applicable
04/10/2023

Additional Computer Science Flashcards

 


 

Cards

Term
How do you group and order the returned query?
Definition
The GROUP BY and ORDER BY clauses can reference the selected columns by number in which they appear in the SELECT statement.
Term
What is the purpose of the SUM() statement?
Definition
The SUM() aggregate function takes the name of a column as an argument and returns the sum of all the value in that column.
Term
What is the sytnax of the SUM() statement?
Definition
SELECT SUM(salary)
FROM salary_disbursement;
Term
What is the MAX() statement used for?
Definition
The MAX() aggregate function takes the name of a column as an argument and returns the largest value in a column.
Term
What is the syntax of the MAX() statement?
Definition
SELECT MAX(amount)
FROM transactions;
Term
What is the COUNT() statement used for?
Definition
The COUNT() aggregate function returns the total number of rows that match the specified criteria.
Term
What is the syntax of the COUNT() statement?
Definition
SELECT COUNT(*)
FROM employees
WHERE experience < 5;
Term
Where is the GROUP BY clause normally located?
Definition
The GROUP BY clause can come after FROM or WHERE but must come before any ORDER BY or LIMIT clause.
Term
What is the MIN() function used for?
Definition
The MIN() aggregate function returns the smallest value in a column.
Term
What is the syntax of the MIN() function?
Definition
SELECT MIN(amount)
FROM transactions;
Term
What is the AVG() function used for?
Definition
The AVG() aggregate function returns the average value in a column.
Term
What is the syntax of the AVG() function?
Definition
SELECT AVG(salary)
FROM employees
WHERE experience < 5;
Term
What is the HAVING clause used for?
Definition
The HAVING clause is used to further filter the result set groups provided by the GROUP BY clause.
Term
Where is the HAVING clause typically located?
Definition
The HAVING clause must always come after a GROUP BY clause but must come before any ORDER BY or LIMIT clause.
Term
What is the syntax of the HAVING clause?
Definition
SELECT year,
COUNT(*)
FROM movies
GROUP BY year
HAVING COUNT(*) > 5;
Term
What is the ROUND() function used for?
Definition
The ROUND() function will round a number value to a specified number of places. It takes two arguments: a number, and a number of decimal places. It can be combined with other aggregate functions
Term
What is the syntax of the ROUND() function?
Definition
SELECT year,
ROUND(AVG(rating), 2)
FROM movies
WHERE year = 2015;
Supporting users have an ad free experience!