Green plum distinct on To Redshift row_number:
Green Plum:
select distinct on
(col_1, col_2, col_3) from table_t1
where condition_1=some_condition order by col_1, col_2, col_3
Rdshift:
select col_1, col_2, col_3 as <alias>
from
(
select row_number() over
(
partition by col_1 order by col_1
) as rn, col_1, col_2, col_3
from table_1
where col_4=<condition>
order by col_1, col_2, col_3
) as t1
where t1.rn=1
Note: If you include more columns for partition by clause, check the no. of row count, as it should be different.
Comments
Post a Comment