-1

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 Answers2

2

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

Bill Weiner
  • 8,835
  • 2
  • 7
  • 18
0

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
;
Jon Scott
  • 4,144
  • 17
  • 29