以下查询在teradata中有效,有没有办法在postgresql中编写相同的查询?运行此ppostgresql 10时出现错误
select *
from
product
qualify
row_number() over (partition by product_key order by product_no) = 1;
答案 0 :(得分:2)
Postgres的distinct on
应该更高效:
select distinct on (product_key) p.*
from product p
order by product_key, product_no;
这通常是Postgres中每组获取一行的最佳方法。
答案 1 :(得分:1)
您需要子查询:
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;