Can somebody tell me how I can convert the following Oracle SQL Statement in PostgreSQL? I don't get it...
SELECT
MAX(TKI1.USER_ID)
KEEP(DENSE_RANK LAST ORDER BY TKI1.UPD_DATE NULLS FIRST)
OVER(PARTITION BY TKI1.NUMBER) AS USER_ID
FROM
USER_TABLE TKI1;
CodePudding user response:
You can use:
SELECT MAX(CASE WHEN rnk = 1 THEN user_id END) OVER (PARTITION BY NUMBER)
AS user_id
FROM (
SELECT user_id,
NUMBER,
RANK() OVER (PARTITION BY NUMBER ORDER BY UPD_DATE DESC NULLS LAST)
AS rnk
FROM user_table
) t