trdsql aggregation calculation
Aggregation calculation
Of course, you can aggregate calculations as well as COUNT() for aggregation. SQL has a set of aggregation functions that perform calculations on numbers.
Here we explain with an example of a CSV file like the following.
SUM
Calculate the sum. Add all the price columns.
As I wrote before, trdsql treats columns as text types, so you need to CAST them to numeric types before calculating them. However, when using aggregation functions, implicit CAST may be omitted (depending on the database you use).
If you want to explicitly CAST, do the following.
AVG
Calculate the average. It can be calculated by sum / number of cases, but it is easier to understand if you use a function. In this example, the meaning of the average may not be so much.
MIN,MAX
Output the minimum and maximum values.
MIN and MAX can be used with text types, so you need to explicitly CAST them.
(You may want to know the name of MIN and MAX, but SQL is a bit complicated, so I’ll do it later).
As I wrote last time, aggregation functions can be executed at once.