2019-04-16 14:13:13 +00:00
|
|
|
DROP TABLE IF EXISTS perf;
|
|
|
|
CREATE TABLE perf (site String, user_id UInt64, z Float64) ENGINE = Log;
|
2018-10-17 04:25:36 +00:00
|
|
|
|
2019-04-16 14:13:13 +00:00
|
|
|
SELECT * FROM (SELECT perf_1.z AS z_1 FROM perf AS perf_1);
|
2018-10-17 04:25:36 +00:00
|
|
|
|
|
|
|
SELECT sum(mul)/sqrt(sum(sqr_dif_1) * sum(sqr_dif_2)) AS z_r
|
|
|
|
FROM(
|
2020-09-08 20:05:47 +00:00
|
|
|
SELECT
|
2018-10-17 04:25:36 +00:00
|
|
|
(SELECT avg(z_1) AS z_1_avg,
|
|
|
|
avg(z_2) AS z_2_avg
|
|
|
|
FROM (
|
|
|
|
SELECT perf_1.site, perf_1.z AS z_1
|
2019-04-16 14:13:13 +00:00
|
|
|
FROM perf AS perf_1
|
2018-10-17 04:25:36 +00:00
|
|
|
WHERE user_id = 000
|
2019-08-29 18:45:34 +00:00
|
|
|
) jss1 ALL INNER JOIN (
|
2018-10-17 04:25:36 +00:00
|
|
|
SELECT perf_2.site, perf_2.z AS z_2
|
2019-04-16 14:13:13 +00:00
|
|
|
FROM perf AS perf_2
|
2018-10-17 04:25:36 +00:00
|
|
|
WHERE user_id = 999
|
2019-08-29 18:45:34 +00:00
|
|
|
) jss2 USING site) as avg_values,
|
2018-10-17 04:25:36 +00:00
|
|
|
z_1 - avg_values.1 AS dif_1,
|
|
|
|
z_2 - avg_values.2 AS dif_2,
|
|
|
|
dif_1 * dif_2 AS mul,
|
|
|
|
dif_1*dif_1 AS sqr_dif_1,
|
|
|
|
dif_2*dif_2 AS sqr_dif_2
|
|
|
|
FROM (
|
|
|
|
SELECT perf_1.site, perf_1.z AS z_1
|
2019-04-16 14:13:13 +00:00
|
|
|
FROM perf AS perf_1
|
2018-10-17 04:25:36 +00:00
|
|
|
WHERE user_id = 000
|
2019-08-29 18:45:34 +00:00
|
|
|
) js1 ALL INNER JOIN (
|
2018-10-17 04:25:36 +00:00
|
|
|
SELECT perf_2.site, perf_2.z AS z_2
|
2019-04-16 14:13:13 +00:00
|
|
|
FROM perf AS perf_2
|
2018-10-17 04:25:36 +00:00
|
|
|
WHERE user_id = 999
|
2019-08-29 18:45:34 +00:00
|
|
|
) js2 USING site);
|
2018-10-17 04:25:36 +00:00
|
|
|
|
2019-04-16 14:13:13 +00:00
|
|
|
DROP TABLE perf;
|