【发布时间】:2021-04-15 15:46:27
【问题描述】:
测试表包含某型火箭发动机的功率测试数据。以下列中的值表示:
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.
您的任务是为每台发动机显示其在三个功率测量中达到最高平均值的测试。但是,您必须考虑以下限制: 1.我们只对参加过至少 5 次测试的引擎感兴趣, 2.对于满足条件 1 的引擎的测试,我们只对持续时间为至少一分钟,并且三个测量值的最小值不小于三个测量值的最大值的 90% 3. 我们只对在满足第 2 点标准后选择的测试满足以下条件的发动机感兴趣条件:给定发动机的三个测试测量结果的最低平均值不低于这些测试中最高测量平均值的 85%。
结果表应包含四列:
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.
我是一名学生,教授在下面给了我这样的作业,我正在发送我的想法来解决这个问题。
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;
【问题讨论】:
-
您从查询中得到了什么结果?它们与您想要的有何不同?