我想在 PostgreSQL 中找到一个未排序列的 n>1 个百分位数。例如第 20、第 40、第 60、第 80 和第 100 个百分位数。
一个明显的解决方案是对列进行计数和排序,然后查看,但我希望有更好的解决方案。有任何想法吗?
PS 我找到了一个很好的 MySQL解决方案,但无法将其转换为 psql
I have table with observations of objects moving along edges in a graph, this table has the following form:
PK | TIMESTAMP | object_id | from_id | to_id
Run Code Online (Sandbox Code Playgroud)
where object_id
is the id of some object and from_id
and to_id
are vertices.
Since the movements are observed at a high frequency the tuple
(object_id, from_id, to_id)
Run Code Online (Sandbox Code Playgroud)
is repeated often for different PK
and TIMESTAMPS
. I'm interested in all the separate edge traversals, so if an object with id 1 …
我有许多带有主键(月、年、数字)的表,不同的基数有所不同。对于元组(月,年),历史不会回溯很远,从长远来看,这可能不会超过 50。对于每个(月、年)元组,不超过 200 万个唯一数字。我想知道哪些月份和年份的组合可用。我使用此查询执行此操作:
select month, year from table group by month, year
这将返回正确的结果,但似乎效率不高。获得此结果的有效方法是什么(利用唯一索引)?
调优顾问建议为该查询添加月-年索引,但这似乎很浪费,因为已经有更大的索引可用。