【问题标题】:find the highest occurrence of a point type查找点类型的最高出现次数
【发布时间】:2020-09-07 05:00:13
【问题描述】:

如何在 PgSQL 中获取点类型数据的最高重复次数

需要计算重复次数最多的坐标(更精确的是100米范围内)

示例数据列名称坐标

user_id                                           coordinates
11ce4d96-4f64-421e-a56d-d436a804e522              (22.34,454.455)
11ce4d96-4f64-421e-a56d-d436a804e522              (12.2323,90.23233)
11ce4d96-4f64-421e-a56d-d436a804e522              (28.6986724,77.2972819)
11ce4d96-4f64-421e-a56d-d436a804e522              (28.6986176,77.2972501)
11ce4d96-4f64-421e-a56d-d436a804e522              (28.6987351,77.2973343)
11ce4d96-4f64-421e-a56d-d436a804e522              (28.6986208,77.2972428)
be34f634-4ab3-4407-89ac-8f79e2d62232              (28.6987699,77.2972538)
be34f634-4ab3-4407-89ac-8f79e2d62232              (28.6987699,77.2972538)
be34f634-4ab3-4407-89ac-8f79e2d62232              (28.6987699,77.2972538)
be34f634-4ab3-4407-89ac-8f79e2d62232              (28.6987699,77.2972538)
be34f634-4ab3-4407-89ac-8f79e2d62232              (28.6987259,77.2972478)
be34f634-4ab3-4407-89ac-8f79e2d62232              (28.6986413,77.2972698)

【问题讨论】:

  • 要求不明确:是找重复还是要找最大的簇?
  • 请添加预期结果和更多解释。
  • 为什么你认为你需要一个存储函数或过程?
  • @a_horse_with_no_name 假设所有数据都属于单个用户,我想找到重复次数最多的坐标,以获取用户的正确位置
  • @Don 。 . .如果你有一个用户,为什么那部分不是示例数据?

标签: sql postgresql plpgsql


【解决方案1】:

这是你想要的吗?

select distinct on (user) user, point(coordinates[0], coordinates[1]), count(*)
from t
group by user, coordinates[0], coordinates[1]
order by user, count(*) desc;

这似乎是你所描述的。

【讨论】:

  • 把这个ERROR: could not identify an equality operator for type point作为坐标是点类型
猜你喜欢
  • 2018-09-23
  • 1970-01-01
  • 1970-01-01
  • 2019-10-27
  • 2015-02-06
  • 2011-04-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多