Я новичок в sql / presto и пытаюсь вычислить радиус вращения для всех usersID, начиная с такой таблицы:
Table
+----------+---------+-------+
| userID | X | Y |
+----------+---------+-------+
| asdasd | 23 | 45 |
| sfasdf | 11 | 12 |
| dfadsg | 93 | 34 |
| asdasd | 17 | 21 |
| dfasdf | 12 | 43 |
| ... | .. | ... |
+----------+---------+-------+
Я хотел бы вернуть таблицу со всеми идентификаторами пользователей и их радиусом вращения.
Мне удалось восстановить код, который вычисляет радиус вращения (rog) случайной выборки из 100 точек, но у меня возникли трудности применить его к моему столу.
with n as (select 100 as n)
--generate a set of points using random XY
, xy as (select SEQUENCE(1,n) as gid, st_point(random(), random()) as geom_point from n)
--distance between each point and centroid
, d as (select gid, st_distance(geom_point, geom_centroid) as dist from xy, c)
--standard deviation of distance
, d_sd as (select stddev(dist) from d)
--square the distance
, d2 as (select gid, dist, dist^2 as dist_squared from d)
--sum the squares and divide by n
, d2sum as (select sum(dist_squared) as dist_squared_sum from d2)
--divide by n
, d2sum_normalize as (select dist_squared_sum / n as dist_norm from d2sum, n)
--square root
, rog as (select sqrt(dist_norm) as radius_of_gyration from d2sum_normalize)
--report radius of gyration and stddev(distance)
select * from rog, d_sd
Спасибо за помощь!