Like most other relational database products, PostgreSQL supports aggregate functions.
An aggregate function computes a single result from multiple input rows. For example, there are aggregates to compute the count, sum, avg (average), max (maximum) and min (minimum) over a set of rows.
MAX
For example if you want to find out the product with highest unit price then we can query like this:
I am using the database available on my Github public repo
SELECT MAX(unit_price) FROM products;
//Output
max
263.5
MIN
if you want to find out the product with lowest unit price then we can query like this:
SELECT MIN(unit_price) FROM products;
//Output
min
2.5
COUNT
If you want to know about the number of products in inventory that you have, we can query like this:
SELECT COUNT(product_id) FROM products;
//Output
count
77
SUM
If you want to know about the total cost of inventory you have, we can query like this:
SELECT SUM(unit_price) FROM products;
//Output
sum
2220.2102
AVG
If you want to know about the average cost of inventory you have, we can query like this:
SELECT AVG(unit_price) FROM products;
//Output
avg
28.83389609200614
We can always round up those numbers using ROUND function.
basics database examples functions sql query