mysql特征缩放计算

mysql feature-scaling calculation(mysql特征缩放计算)
本文介绍了mysql特征缩放计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要制定一个 mysql 查询来选择以这种方式标准化的值:标准化 = (value-min(values))/(max(values)-min(values))我的尝试如下所示:

I need to formulate a mysql query to select values normalized this way: normalized = (value-min(values))/(max(values)-min(values)) My attempt looks like this:

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'

但显然是错误的,因为它只返回一个值.你能帮我找到正确的语法吗?

but is obviously wrong as it returns only one value. Can you help me finding the correct syntax?

推荐答案

你的问题解释有点短,但我认为你需要窗口函数(仅在 MySQL 8.0 中可用):

Your question is a little short on explanations, but I think that you want window functions (available in MySQL 8.0 only):

select 
    time, 
    value,
    (value - min(value) over() / (max(value) over() - min(value) over()) normalized_value
from measurement_values  
where measure_id = 49 and time >= '2020-05-30 00:00'

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

Or, in earlier versions, you can get the same result by joining the table with an aggregate query:

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特征缩放计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)