SQL aggregate functions
SQL aggregate functions
The following are the most commonly used SQL aggregate functions:
Notice that all aggregate functions above ignore NULL values except for
the COUNT function.
SELECT
To calculate units in stock by product category, you use the AVG function
with the GROUP BY clause as follows:
SELECT
SELECT
categoryid, SUM(unitsinstock)
FROM products GROUP BY categoryid;
.
To get the minimum units in stock of products in the products table, you
use the MIN function as follows:
SELECT
MIN(unitsinstock)
FROM
products;
To get the maximum units in stock of products in the products table, you
use the MAX function as shown in the following query:
SELECT
MAX(unitsinstock)
FROM
products;