下面的查询在 teradata 中有效,有没有办法在 postgresql 中编写相同的查询?我在运行 ppostgresql 10 时遇到错误
select *
from
product
qualify
row_number() over (partition by product_key order by product_no) = 1;
Run Code Online (Sandbox Code Playgroud)
Gor*_*off 12
Postgres 有distinct on,它应该具有更高的性能:
select distinct on (product_key) p.*
from product p
order by product_key, product_no;
Run Code Online (Sandbox Code Playgroud)
这通常是 Postgres 中每组获取一行的最佳方法。
您需要子查询:
select p.*
from (select p.*,
row_number() over (partition by product_key order by product_no) as seq
from product p
) p
where seq = 1;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16317 次 |
| 最近记录: |