postgresql - PostgreSql 找到第 n 个数字
问题描述
编写一个在列中找到第三大整数的聚合?这就是我正在做的事情:
create function third_step(bigint, integer) returns bigint AS
$$
SELECT distinct
* from count_lab order by ab asc limit 1 offset 2 ;
$$ language sql; --can we use plpgsql somehow?
create aggregate third_agg(integer)
(stype=bigint,sfunc=third_step,initcond=0);
SELECT distinct
* from count_lab order by ab asc limit 1 offset 2 ;
解决方案
它应该是:
SELECT DISTINCT ab
FROM count_lab
WHERE ab IS NOT NULL
ORDER BY ab DESC
LIMIT 1 OFFSET 2;
推荐阅读
- php - AddSelect 在 searchQueryBuilder 使用条件
- spring - 我怎样才能阻止我的整个工作从并行流中?
- macos - 在 MacO 上将 at 和 batch 实用程序与 zsh 一起使用
- javascript - Django 无法解析剩余的 javascript
- javascript - 我必须从数据库输出我的数据,还必须从表单中复制所有输入以将它们发送给我自己,包括实时乘法 weight*pcs
- import - 更改导入参数功能模块abap的值
- maven - 如何使用 p2-maven-plugin 包含到本地 p2-site 非 JAR 文件?
- ios - Flutter 无法构建 IOS 存档
- c# - Blazor 级联组件防止 StateHasChanged
- relationship - 使用 DirectQuery 在 PowerBI 中转换表列名称会删除该表的所有关系