Hi all,
We are migrating from oracle to teradata, and got stuck with dense_rank function, please any suggestions would be appreciate.
Here is our query in oracle:
select
dense_rank() OVER (ORDER BY STATE) AS STATE_KEY,
COALESCE(columnA, 'Other')
from tableA
left outer join tableB on tableA.sk1 = tableB.sk1
left outer join tableC on tableA.sk2 = tableC.sk2
We've looked some threads and converted into following, but not working properly
SELECT
--,DENSE_RANK() OVER (ORDER BY STATE) -- not implemented,
COALESCE(columnA, 'Other'),
SUM(CASE WHEN STATE = prev_STATE THEN 0 ELSE 1 END)
OVER (
ORDER BY STATE, prev_STATE
ROWS UNBOUNDED PRECEDING) AS STATE_KEY
FROM
(
SELECT
STATE
,MIN(STATE) OVER (ORDER BY STATE
ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING) AS prev_STATE
FROM tableA
left outer join tableB on tableA.sk1 = tableB.sk1
left outer join tableC on tableA.sk2 = tableC.sk2
)