Sample Header Ad - 728x90

Substitute DISTINCT ON for query transformation (Postgresql to Redshift)

0 votes
1 answer
1100 views
I need to transform my Postgresql query to Redshift and I working with the following data, here is an excerpt: enter image description here In my final output, I would like only to keep rows with the highest rank (in green). And I was using the following query, which works to get the output, but I have to transform it into Redshift because the visualization tool is only using Redshift and Redshift doesn't recognize DISTINCT ON.
select distinct on customer_id
id_created,
customer_id,
call_start,	
status_prior,	
status_after,	
rank() over (partition by customer_id order by call_start) as rank
order by customer_id, rank desc;
Asked by ColRow (43 rep)
Jun 30, 2020, 08:50 PM
Last activity: Sep 14, 2021, 10:04 AM