sql - how to compare value of new calculated column in postgresql -


i runnning query

  select      case when "payment collection fee" = 0      round(("comm (incl. s.tax)" - ((("marketing fee" *16)/100)+"marketing fee"+0+"courier fee")),2)      when "web sale price" < 0 round(("comm (incl. s.tax)" - ((("marketing fee" *16)/100)+"marketing fee"-20+"courier fee")),2)      else        round(("comm (incl. s.tax)" - ((("marketing fee" *16)/100)+"marketing fee"+20+"courier fee")),2)      end diff         meta.sd_payment_error 

now want add condition

  diff > 10  

but giving error diff column not exist

how can add condition above query ?

you can use common table expression :

with diffs (   select      case      when "payment collection fee" = 0        round(("comm (incl. s.tax)" - ((("marketing fee" *16)/100)+"marketing fee"+0+"courier fee")),2)      when "web sale price" < 0         round(("comm (incl. s.tax)" - ((("marketing fee" *16)/100)+"marketing fee"-20+"courier fee")),2)      else        round(("comm (incl. s.tax)" - ((("marketing fee" *16)/100)+"marketing fee"+20+"courier fee")),2)      end diff        meta.sd_payment_error ) select diff diffs diff > 10 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -