Learning Series #12: AGGREGATE Functions

Tomisin Agbaje
2 min readApr 16, 2024

--

With yesterday’s lesson on LIKE & ILIKE, I concluded the basic SQL statements lessons. I did enjoy the introductory phase. It felt like a soft cushion to land on. The remaining parts of the lecture appear progressively complex.

Moving my thoughts aside, I learnt some aggregators used in SQL. These aggregators are used to make more complex queries and can be combined with simple SQL operators. Some of the aggregators mentioned include

Average (Denoted by AVG ())

AVG () : This refers to the average function and can be used to query the average of specified column names within a table.

SELECT AVG (price) FROM accounts;

The query above shows that we are attempting to get the average price from the account table. The results gotten might be in decimals and include floating numbers. With the ROUND operator, we can wrap up the floating number into the nearest decimals.

This will look like

SELECT ROUND (AVG (price), 2) FROM accounts;

This tells us that the average price should be rounded up into 2 decimal figures. So if the response was 3.14159265359, it would then become 3.14.

Maximum (MAX () and Minimum (MIN ())

MAX() This is used to find the maximum value within a column.

MIN() This operator helps find the minimum value within the column

SELECT MAX price FROM accounts;

With this query, we are trying to find the highest price within the accounts table. The same syntax is used for MIN

Other operators touched on include SUM() used to do a total sum of specified columns, COUNT is used to total values within a sum.

I just ran a few more queries with the same just to test how it works. I have found that I have currently hit a roadblock with my practice questions. For some of the questions, I am yet to learn the functions.

It is being fun.

Until next time,

Cheers!

--

--