PostgreSQL
 sql >> Base de Dados >  >> RDS >> PostgreSQL

Dense_rank é a primeira conversão de Oracle para Postgresql


Acho que você pode convertê-lo para conter um único DENSE_RANK() e faça um MAX de todos no primeiro disco.
SELECT UID,
       MAX(OWNER),
       MAX(EMPLOYEE_KEY),
       MAX(MANAGER),
       MAX(CALL_CENTER_NAME),
       MAX(CITY)
  FROM (SELECT ai.UID,
               ai.OWNER AS OWNER,
               ai.EMPLOYEE_KEY AS EMPLOYEE_KEY,
               ai.MANAGER_LOGIN AS MANAGER,
               ai.CALL_CENTER_NAME AS CALL_CENTER_NAME,
               ai.CITY AS CITY,
               DENSE_RANK () OVER (PARTITION BY ai.UID ORDER BY ai.AGENT_ID DESC) rnk
          FROM agent_info ai
         WHERE TRANSLATE (ai.UID, 'X0123456789', 'X') IS NULL)
 WHERE rnk = 1
GROUP BY UID;