MySQL数学-是否可以计算查询中的相关性? [英] MySQL Math - Is it possible to calculate a correlation in a query?

查看:34
本文介绍了MySQL数学-是否可以计算查询中的相关性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MySQL(5.1)数据库表中,有表示以下内容的数据:

In a MySQL (5.1) database table there is data that represents:

  • 用户执行任务需要多长时间,并且
  • 用户在任务期间处理了多少个项目.

MySQL是否支持关联数据,还是需要使用PHP/C#进行计算?

Would MySQL support correlating the data or do I need to use PHP/C# to calcuate?

在哪里可以找到一个好的公式来计算相关性(距离我上次这样做已经很长时间了?)

Where would I find a good formula to calculate correlation (it's been a long time since I last did this)?

推荐答案

这里是样本相关系数的粗略实现,如以下所述:

Here's a rough implementation of the sample correlation coefficient as described in:

维基百科-相关性和依赖性

create table sample( x float not null, y float not null );
insert into sample values (1, 10), (2, 4), (3, 5), (6,17);

select @ax := avg(x), 
       @ay := avg(y), 
       @div := (stddev_samp(x) * stddev_samp(y))
from sample;

select sum( ( x - @ax ) * (y - @ay) ) / ((count(x) -1) * @div) from sample;
+---------------------------------------------------------+
| sum( ( x - @ax ) * (y - @ay) ) / ((count(x) -1) * @div) |
+---------------------------------------------------------+
|                                       0.700885077729073 |
+---------------------------------------------------------+

这篇关于MySQL数学-是否可以计算查询中的相关性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆