skip to Main Content

I have this code in tableau which I need to convert to Redshift SQL

(
zn(
 sum([Market_Price])
  )-
zn(
 sum(
   if ISNULL([Market_Price]) then null else [Initial_Price] end
    )
))/
zn(sum([Market_Price]))

I have tried but not getting the same results.
Do we have isnull and zn equivalent in Redshift?

2

Answers


  1. You can replace zn(X) with nvl(X,0)

    Login or Signup to reply.
  2. Something like this should work

    select (
      coalesce(sum("Market_Price"),0) -
      coalesce(sum(case when "Market_Price" is null then null else "Initial_Price" end ),0) 
            ) / sum("Market_Price")
    from your_redshift_table
    ;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search