mysql特征缩放计算

mysql特征缩放计算,mysql,sql,mariadb,window-functions,feature-scaling,Mysql,Sql,Mariadb,Window Functions,Feature Scaling,我需要制定一个mysql查询来选择这样规范化的值: normalized=(值最小(值))/(最大(值)-min(值)) 我的尝试如下所示: select Measurement_Values.Time, ((Measurement_Values.Value-min(Measurement_Values.Value))/(max(Measurement_Values.Value)-min(Measurement_Values.Value))) from Measuremen

我需要制定一个mysql查询来选择这样规范化的值:
normalized=(值最小(值))/(最大(值)-min(值))
我的尝试如下所示:

select 
    Measurement_Values.Time, 
    ((Measurement_Values.Value-min(Measurement_Values.Value))/(max(Measurement_Values.Value)-min(Measurement_Values.Value))) 
from Measurement_Values  
where Measurement_Values.Measure_ID = 49 and Measurement_Values.time >= '2020-05-30 00:00'
但显然是错误的,因为它只返回一个值。
您能帮我找到正确的语法吗?

您的问题解释得有点简短,但我认为您需要窗口函数(仅在MySQL 8.0中提供):

或者,在早期版本中,您可以通过将表与聚合查询联接来获得相同的结果:

select 
    mv.time, 
    mv.value,
    (mv.value - mx.min_value) / (mx.max_value - mx.min_value) normalized_value
from measurement_values  
cross join (
    select min(value) min_value, max(value) max_value
    from measurement_values
    where measure_id = 49 and time >= '2020-05-30 00:00'
) mx
where measure_id = 49 and time >= '2020-05-30 00:00'

您的问题的解释有点简短,但我认为您需要窗口函数(仅在MySQL 8.0中提供):

或者,在早期版本中,您可以通过将表与聚合查询联接来获得相同的结果:

select 
    mv.time, 
    mv.value,
    (mv.value - mx.min_value) / (mx.max_value - mx.min_value) normalized_value
from measurement_values  
cross join (
    select min(value) min_value, max(value) max_value
    from measurement_values
    where measure_id = 49 and time >= '2020-05-30 00:00'
) mx
where measure_id = 49 and time >= '2020-05-30 00:00'

非常感谢。我在MariaDB 10.4(带有窗口函数)上尝试了您的第一个解决方案。当我在每个over()中添加一个partitionby(measure_id)子句时,它就起作用了。如果我的答案正确回答了您的问题,请单击复选标记。谢谢,谢谢!我在MariaDB 10.4(带有窗口函数)上尝试了您的第一个解决方案。当我在每个over()中添加一个partitionby(measure_id)子句时,它就起作用了。如果我的答案正确回答了您的问题,请单击复选标记。谢谢