Get a Quote Right Now

Edit Template

Simple Aggregate Functions

  1. COUNT: Counts the number of rows that match a specified condition.
  2. SUM: Calculates the sum of the values in a numeric column.
  3. AVG: Computes the average value of the values in a numeric column.
  4. MIN: Retrieves the minimum value from a column.
  5. MAX: Retrieves the maximum value from a column.
  6. GROUP_CONCAT: Concatenates values from multiple rows into a single string.
  7. STDEV: Calculates the standard deviation of a set of values.
  8. VAR: Calculates the variance of a set of values.
  9. FIRST: Returns the first value in a column.
  10. LAST: Returns the last value in a column.

COUNT: The COUNT function is used to count the number of rows in a result set that meet a certain condition. It is often used to count the occurrences of a particular value or to retrieve the total number of rows in a table.

SELECT COUNT() FROM orders; -- Count all rows in the "orders" table SELECT COUNT() FROM customers WHERE age > 30; -- Count customers older than 30

SUM: The SUM function calculates the sum of a numerical column’s values in a result set. It’s commonly used to find the total of a specific numeric attribute.

SELECT SUM(price) FROM products; -- Calculate the total price of all products

AVG: The AVG function computes the average of a numerical column’s values in a result set. It’s used to find the average value of a specific numeric attribute.

SELECT AVG(age) FROM employees; -- Calculate the average age of employees

MIN: The MIN function returns the minimum value from a column in a result set. It’s used to find the smallest value in a numeric or character column

SELECT MIN(salary) FROM staff; -- Find the lowest salary among staff members

MAX: The MAX function retrieves the maximum value from a column in a result set. It’s used to find the largest value in a numeric or character column.

SELECT MAX(score) FROM test_results; -- Find the highest test score

These simple aggregate functions (COUNT, SUM, AVG, MIN, and MAX) are fundamental tools in SQL for performing calculations and summarizing data in various ways. They are used extensively for generating insights and reports from database tables.

Share

Leave a Reply

Your email address will not be published. Required fields are marked *