Oracle Statement with DENSE_RANK FIRST ORDER BY in Postgres

1.6k views Asked by At

Can somebody tell me how I can convert the following Oracle SQL Statement in Postgres SQL? I don't get it...

SELECT MIN(t2.id) KEEP (DENSE_RANK FIRST ORDER BY t2.edit_date) AS id 
  FROM temp t2 
 GROUP BY t2.sku
1

There are 1 answers

4
Gurwinder Singh On BEST ANSWER
SELECT MIN(t2.id) OVER (ORDER BY t2.edit_date) AS id 
FROM temp t2 
GROUP BY t2.sku

EDIT:

Even though above did what OP asked, the equivalent for the given query can be:

select min(t.id) id 
from
  (select t.*,
   dense_rank() over (order by t.edit_date) AS rnk 
   from temp t) t
where rnk = 1
group by t.sku;