Extracting the maximum of several subsets and join all maximums in a new table I have a big table:



What I need is to obtain the maximum value for each testname, with different entry and get a new table such as:



And then I want to compute the maximum, the minimum and the average value for this new table.

Can you help me?
First step:

SELECT testname, entry, MAX(`value`) as max_value
FROM your_table
GROUP BY testname, entry


Second step:

SELECT MAX(max_value), MIN(max_value), AVG(max_value)
FROM ( /*here we insert the query from the first step*/
    SELECT testname, entry, MAX(`value`) as max_value /*rename the column so we can conveniently access it from the outer query*/
    FROM your_table
    GROUP BY testname, entry
) sq /*sq is an alias for the subquery, it's needed*/