MySQL Math - 可以在查询中计算相关性吗?

Joh*_*n M 8 mysql math

在MySQL(5.1)数据库表中,有数据表示:

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

MySQL会支持关联数据还是需要使用PHP/C#来计算?

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

Mar*_*tin 15

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

维基百科 - 相关与依赖

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 |
+---------------------------------------------------------+
Run Code Online (Sandbox Code Playgroud)