Functions

Aggregate functions combine multiple rows together to form a single value of more meaningful information.

COUNT

COUNT() function counts the number of rows that match the specified criteria

SELECT COUNT(*)
FROM table_name;

SUM

SUM() function returns the sum of the values in a column

SELECT SUM(column)
FROM table;

MAX/ MIN

MAX() and MIN() functions return the highest and lowest values in a column respectively.

SELECT MAX(column)
FROM table;

AVG

AVG() function returns the average of the values in a column

SELECT AVG(column)
FROM table;

ROUND

ROUND() function takes two arguments inside the parenthesis:

  • a column name
  • an integer It rounds the values in the column to the number of decimal places specified by the integer.
SELECT ROUND(column, 0)
FROM table;

In the code above, SQL rounds the values in the column to 0 decimal places in the output.

GROUP BY

GROUP BY is a clause used with aggregate functions to combine data from one or more columns.

HAVING

HAVING limit the results of a query based on an aggregate property.