Aggregate Functions In MySQL Flashcards
What are aggregate functions in MySQL used for?
To perform calculations on a set of values and return a single value as a result
What does the COUNT() function do?
Counts the number of rows that meet a specified condition
What is the syntax for the COUNT() function?
COUNT(column_name)
or COUNT(*)
Provide an example of using COUNT() in SQL.
SELECT COUNT(*) FROM customers
What does the SUM() function calculate?
The sum of values in a specified column
What is the syntax for the SUM() function?
SUM(column_name)
Provide an example of using SUM() in SQL.
SELECT SUM(amount) FROM orders
What does the AVG() function calculate?
The average value of a specified column
What is the syntax for the AVG() function?
AVG(column_name)
Provide an example of using AVG() in SQL.
SELECT AVG(price) FROM products
What does the MIN() function return?
The minimum value of a specified column
What is the syntax for the MIN() function?
MIN(column_name)
Provide an example of using MIN() in SQL.
SELECT MIN(order_date) FROM orders
What does the MAX() function return?
The maximum value of a specified column
What is the syntax for the MAX() function?
MAX(column_name)
Provide an example of using MAX() in SQL.
SELECT MAX(salary) FROM employees
What is the purpose of the GROUP BY clause?
To group the results based on one or more columns
What is the syntax for using aggregate functions with GROUP BY?
SELECT column_name, aggregate_function(column_name) FROM table_name GROUP BY column_name
Provide an example of using GROUP BY with COUNT() in SQL.
SELECT country, COUNT(*) FROM customers GROUP BY country
Do aggregate functions ignore NULL values?
Yes, except for COUNT(*)
What keyword can be used within COUNT() to count distinct values?
DISTINCT
What are some additional aggregate functions mentioned?
- GROUP_CONCAT()
- STDDEV()
- VARIANCE()
Fill in the blank: Aggregate functions are often used in combination with other clauses like _______ and _______ to filter results.
[WHERE, HAVING]