It depends on which database engine you are using. Normally there are SQL "aggregate" commands for Count, Max, Min, Sum, Avg, sometimes also StdDev etc. You can call them in the query which you need to extract data from the database. I am attaching an example based on SQLite3 which does not support StdDev, but it is easy to calculate it from the SUM command.
If you are using a simple desktop dataset like TBufDataset which does not offer SQL you must iterate through all records and calculate the values manually. It's easy -- I would not use any third-party components for this job.