The table tests contains data on power tests of a certain type of rocket engine. The values ​​in the following columns mean:

```
ID - test number
SN - engine serial number
T - test duration in seconds
M1, M2, M3 - power values ​​recorded at the beginning, half and end of the test duration.

```

Your task is to display for each engine the test in which it achieved the highest average value of three power measurements. However, you must take into account the following limitations: 1.we are only interested in those engines that have participated in at least 5 tests, 2.of the tests for engines that meet condition 1, we are only interested in those that lasted at least a minute and where the lowest value of the three measurements was not less than 90% of the highest value of the three measurements 3. We are interested only in those engines for which the tests selected after meeting the criteria in point 2 meet the following condition: the lowest average of the three measurement results of the tests for a given engine is not less than 85% of the highest average of measurements among these tests.

The resulting table should contain four columns:

```
ID
SN
MAX - containing the highest value of the three measurements in the given test
MAX_AVG - containing the highest average of measurements from all tests for a given engine (taking into account the conditions described above). Round this value to two decimal places.
Sort the results from the highest to the lowest average.

```

I am a student and the professor gave me such an assignment below I am sending my idea to solve this problem.

```
SELECT
  ID, SN, AS MAX(M1, M2, M3) AS MAX, ROUND(MAX((M1 + M2 + M3)/3.0),2) AS MAX_AVG
FROM
  tests
WHERE
      T >= 60
  AND MIN(M1, M2, M3) >= MAX(M1, M2, M3) * 0.9
GROUP BY
  SN
HAVING
      COUNT(SN) >= 5
  AND MIN((M1 + M2 + M3)/3.0) >= MAX((M1 + M2 + M3)/3.0) * 0.85
ORDER BY
  MAX_AVG ASC;

```