basic-math
Counting Results
To count rows you can use the COUNT() function.
SELECT COUNT(*) FROM <table>;To count unique entries use the DISTINCT keyword too:
SELECT COUNT(DISTINCT <column>) FROM <table>;To count aggregated rows with common values use the GROUP BY keywords:
SELECT COUNT(<column>) FROM <table> GROUP BY <column with common value>;Obtaining Totals
To total up numeric columns use the SUM() function.
SELECT SUM(<numeric column) FROM <table>;
SELECT SUM(<numeric column) AS <alias> FROM <table>
GROUP BY <another column>
HAVING <alias> <operator> <value>;Calculating Averages
To get the average value of a numeric column use the AVG() function.
Finding the Maximum and Minimum Values
To get the maximum value of a numeric column use the MAX() function.
To get the minimum value of a numeric column use the MIN() function.
Mathematical Operators
*Multiply/Divide+Add-Subtract
Last updated
Was this helpful?