I am trying to figure out an SQL query to get aggregate calculations from a data table. The data table is a simple list of dates and data (real). I am simply trying to get the AVG, MAX, and MIN of the top 100 data points in descending order. There are several thousand data points in the table. The Select statement I have used that does not work is:
SELECT TOP 100 Cur_Date, AVG(DataMean) AS DMEAN, MAX(DataMean) AS DMAX, MIN(DataMean) AS DMIN FROM DataTable WHERE PartNumber = ? ORDER BY Cur_Date DESC.
Can anyone help?
Thanks,
Maybe you're missing a GROUP BY some_column criteria for which you want to calculate the aggregated values?
Please see the link below for basic aggregations concept/queries and hopefully they help you solve your problem.
https://www.zentut.com/sql-tutorial/sql-aggregate-functions/